aspose file tools*
The moose likes Threads and Synchronization and the fly likes Stopped threads? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Stopped threads?" Watch "Stopped threads?" New topic
Author

Stopped threads?

Ashish Chopra
Ranch Hand

Joined: Nov 30, 2004
Posts: 134
I have a scenario where my application has ~12000 threads that are being displayed as stopped in my profiler. However, the memory usage figures shown are very high, and they go on increasing as more threads go in stopped state.

My question is, when a thread goes into stopped state, does it release all resources held by it, or does it hold on to them?

If it holds on, is there a way to free these resources?

Thanks in advance


Quis Custodiet Ipsos Custodes<br /> <br />My blog: <a href="http://www.coherentrambling.blogspot.com" target="_blank" rel="nofollow">http://www.coherentrambling.blogspot.com</a>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41853
    
  63
Why would the resources be freed? The thread is still alive, and could be woken up at any time. The better question is: Why is there a need to keep 12000 of them around even if though there're stopped? Maybe there's a way that allows the threads to be discarded when they're not used.


Ping & DNS - my free Android networking tools app
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
If the many threads have finished executing, then the JVM should release the associated Thread objects. If the threads are suspended (naughty), in wait(), waiting for a monitor or something like that, but still alive, then they cannot be released, because they might come back to life at any time.

The Thread objects won't be released if something in your code is holding a reference to them. Perhaps you're storing them all in a collection, or something like that.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Ashish Chopra
Ranch Hand

Joined: Nov 30, 2004
Posts: 134
Well, actually all these threads are transient threads that are created for notification purposes in the application.

Also, the profiler is displaying all these threads as stopped, not waiting.

Is it possible for me to free the resources that are held up in these stopped threads?
[ March 29, 2006: Message edited by: Ashish Chopra ]
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Try reading the previous responses.
Ashish Chopra
Ranch Hand

Joined: Nov 30, 2004
Posts: 134
Peter, as I said, these threads are not in waiting state, they are clearly shown as being in stopped state.

And in case the Garbage collector would have reclaimed memory & resources from these threads, they wouldn't be in stopped state, but killed already.

This is why I ask, is there a way I can force removal of these stopped threads?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Are you holding a reference to the Thread objects in a collection or something? If it's stopped it should be eligible for GC unless other code does something to prevent it.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ashish Chopra
Ranch Hand

Joined: Nov 30, 2004
Posts: 134
No, these threads are transient threads that are launched, they perform some functionality, and then exit. I am not maintaining any collection where these references are stored.

And I am using the runnable interface based implementation of threads...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stopped threads?