IntelliJ Java IDE
The moose likes Threads and Synchronization and the fly likes How Get Inactive Threads of a ThreadGroup? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How Get Inactive Threads of a ThreadGroup?" Watch "How Get Inactive Threads of a ThreadGroup?" New topic
Author

How Get Inactive Threads of a ThreadGroup?

Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
ThreadGroup has a way to get all active threads of that thread group (enumerate). I can also get a list of the names of all active AND inactive threads (list). Does anyone know how I can actually get a reference to the inactive threads?
With enumerate, I can get actual references to the thread objects:
<ThreadGroup>.enumerate(Thread[] list, boolean recurse);
And I know the ThreadGroup has a reference to the inactive threads as well, because list will show the inactive threads too:
<ThreadGroup>.list();
Thanks!
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
anyone? I can't find the answer anywhere, but really need to be able to do this! help!
Robert Paris
Ranch Hand

Joined: Jul 28, 2002
Posts: 585
OK, here's how you do it:

A couple things:
1. You need to set the field accessible even without a security manager
2. If you have security on, you'll need the runtime permission "suppressAccessChecks" even though I know most people run with no security or "AllPermission".
3. That check for null is important! I believe it keeps more room than it needs, so it doesn't have to expand all the time, so you don't want to hit a null pointer.
Have fun!
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Great! Now I think that I will move this to the Threads forum .


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
jQuery in Action, 2nd edition
 
subject: How Get Inactive Threads of a ThreadGroup?
 
Threads others viewed
java threads
thread scope
what's running on my VM?
getting thread names
activeCount Gives worng number :argh:
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture