• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Verifying if a thread is alive

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would the Thread methods getName() and isAlive() serve your purpose?
[ June 24, 2003: Message edited by: Marlene Miller ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic