File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes how to suspend thread using thread's id? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "how to suspend thread using thread Watch "how to suspend thread using thread New topic
Author

how to suspend thread using thread's id?

Happy S Singh
Ranch Hand

Joined: Nov 14, 2011
Posts: 52
Code which I am trying



How can we suspend/pause thread based on its id
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Happy S Singh wrote:Code which I am trying



How can we suspend/pause thread based on its id


First, suspend() is a deprecated method. And it is deprecated because under really rare situations, it was possible to suspend a thread that is owning one of the JVMs internal locks. This will effectively "break" the JVM.

But to answer your question.... You will need to have a collection of Thread objects to search through -- just enumerate through the list to find it. If your application didn't maintain the list, then one option would be to .... (1) start with the current thread, (2) get the thread group and check all the threads own by that thread group, (3) thread groups also own thread groups, so you can also (3a) move up to the parent threadgroup of the current threadgroup and repeat and/or (3b) enumerate the threadgroups own by current threadgroup and repeat (recursively).

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to suspend thread using thread's id?