aspose file tools
The moose likes Threads and Synchronization and the fly likes Verifying if a thread is alive Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Verifying if a thread is alive" Watch "Verifying if a thread is alive" New topic
Author

Verifying if a thread is alive

David Duran
Ranch Hand

Joined: Feb 11, 2002
Posts: 122
I have a program that starts several new threads, all of which loop infinitely, each taking time to sleep between execution of it's own code.
My question is this- If I name the threads from my main "hub" (the program which starts all the threads), is there a way for me to use the Thread name to verify whether or not that that thread is still running after x amount of time?
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Would the Thread methods getName() and isAlive() serve your purpose?
[ June 24, 2003: Message edited by: Marlene Miller ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Your "hub" thread could just store an ArrayList or something containing references to the threads it has created. Then later you can loop through the list and check isAlive() on each one. I don't think you need the name for this, but maybe you will want to assign meaningful names for readability or something.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Verifying if a thread is alive
 
Similar Threads
TimerTask, Thread
class won't daemonize
doubt from scjp book on threads
threads + unique random numbers
main app won't stop when all threads are done running