Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent : Stop a thread from a Class diff from its creation Class

Status
Not open for further replies.

sikar

Programmer
Jun 4, 2003
15
US
In my program I create a thread and name it test and call its run method from a Java Class(file). Now on click of some button in a different Class I want to stop this 'test' thread. I list down all the active threads in my java class(in which I want to stop this 'test' thread) and if the name of any active thread matches 'test' I want to stop it. How can I achieve this??? I need to do this urgently. Please reply at the earliest.


Thanks
Sikar
 
If you want to look for the thread, you can iterate into the ThreadGroup of the current thread and outside it with its getParent method.

If you want to stop the Thread you can use the interrupt call to do it or even the destroy to do it by brute force.

Cheers.

Dian
 
I iterated through the Threadgroups and got an array of active threads.
Thread thread = threads;

if(thread.getName().equalsIgnoreCase("test")) {
thread = null // This is not stopping the thread
}

Now how can I stop or destroy the 'test' thread.

Thanks
Sikar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top