Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java Language
Expertise: Beginner
May 13, 1997



Application Security Testing: An Integral Part of DevOps

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

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.

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() {
      // etc.

   public void stop() {
      // etc.

   // etc.
Each time the user leaves the page, stop() is automatically called, and each time the user moves back onto the page, start() is automatically called.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date