• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Which threads are still alive

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Morning all,

In a multi-threaded application, is there any way of discovering/listing which threads (thread names) are still "alive", i.e. have not yet finished their run() method? I mean programmatically not using some monitor.

I know I can find out how many are active using Thread.activeCount() but is there an array or something lying around that holds the names for those threads?

I don't mean all the threads associated with the JVM's process of running the application, i.e. garbage collection, etc. just the ones related to the application, main, thread1, thread2, etc.

I'm guessing that there's no way of finding out the status of the active threads since by the time you've got that the status will probably have changed anyway.

Thanks for all your help, really appreciate it.
Regards,
Phil.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Phil:
Morning all,



I think ranch must specify a variable in the editor that changes with the time zones. As it is afternoon here in India
Anyways, coming to serious matters.

Phil:
In a multi-threaded application, is there any way of discovering/listing which threads (thread names) are still "alive", i.e. have not yet finished their run() method? I mean programmatically not using some monitor.



Well yes you can find out.
Thread.enumerate(Thread[] tarray) is the method that does it for you.
But that method will list only the threads that are a part of the current thread thread group.
If you need to find threads for your application, you can make sure that all your threads have a known thread group.

Phil:
I'm guessing that there's no way of finding out the status of the active threads since by the time you've got that the status will probably have changed anyway.



Well, i would say that there is a way but the information retrieved may be outdated by the time you read it.
[ September 10, 2008: Message edited by: Nitesh Kant ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One option is to use JMX - the JConsole tool will show all threads.

If you want to do it programmatically, check out the code I posted in this thread.
 
Phil Hopgood
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf, Nitesh,

Thanks for that guys.

More stuff to play with

Regards,
Phil
 
Always! Wait. Never. Shut up. Look at this tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic