devxlogo

How to kill/dispose of applet thread when you leave page

Question:
I have an applet placed on successive pages that displays different information on each page (a text-scrolling applet). This applet is running on a thread. Is there a way to kill or dispose of this thread when you leave the page on which it was created? I have noticed that from time to time that when I quit using the browser, I can still see the applet scrolling across until Netscape completely disposes of all its memory.

Answer:
The convention is to create threads in init(), start them in start(),and stop them in stop():

public class MyApplet extends Applet {   private MyThread scroller;   public void init() {      scroller = new MyThread(…);      // etc.   }    public void start() {      scroller.start();      // etc.   }   public void stop() {      scroller.stop();      // etc.   }   // etc.}
Each time the user leaves the page, stop() is automaticallycalled, and each time the user moves back onto the page, start() is automatically called.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Seven Service Boundary Mistakes That Create Technical Debt

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.