Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Verifying if a thread is alive  RSS feed

 
David Duran
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would the Thread methods getName() and isAlive() serve your purpose?
[ June 24, 2003: Message edited by: Marlene Miller ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!