I'm working on struts 2 framework. I've a requirement as when user hits a specific url i need to enable a functionality and after some minutes have to disable the same process. All these will be running at background when hitting the url. So I've decided to go with Threads for it. Following is the code I'm using...
public class ActDeactTrace extends Thread {
@Override
public void run() {
System.out.println("RUNNING THREAD...BEFORE SLEEP");
enableTrace();
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("RESUMED THREAD .... AFTER WAKE UP");
disableTrace();
super.run();
}
public void enableTrace(){
}
public void disableTrace(){
}
}
When the action is invoked from the user i just start the Thread through its object. Since it is a web app, many users can do the same. So should i manually destroy the created thread after the disableTrace method is executed to avoid JVM problems or will it automatically get destroyed by garbage collectors.