wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes How to find elapsed time for ThreadPool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "How to find elapsed time for ThreadPool" Watch "How to find elapsed time for ThreadPool" New topic
Author

How to find elapsed time for ThreadPool

Sify Alto
Greenhorn

Joined: Mar 22, 2010
Posts: 13
Hi Friends,
I want to find the elapsed time for my multithreaded program.I have used ThreadPoolExecutor to manage threads.When I am not using the Thread pools,I used to use join() in the main method,so that my main thread will not terminate before the child threads terminate and hence I am able to find elapsed time.But when I use Thread pool ,even if I use join(),the main thread terminates before the child threads,so I am unable to calculate elapsed time.
I have attached a part of the code for your reference.Please help me.



I tried using a 'for' loop after pool.shutdown() instead of the pool.awaitTermination(, , )
But it did not work for me,the main thread terminates before the other threads.
Your help is appreciated.

Sify
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4167
    
  21

ThreadPoolExecutor also has a method named 'isTerminated()'. You could put an awaitTemination(...) with a relatively small timeout into a while loop that checks isTerminated(), such that you continue to accumulate time until the ThreadPoolExecutor actually ends.

Or you could extend ThreadPoolExecutor and implement the timing mechanism in it, using the protected method terminated() to report back either that it is done, or to report how long it ran.


Steve
Sify Alto
Greenhorn

Joined: Mar 22, 2010
Posts: 13
Thank you Steve for your guidance.The while loop worked perfectly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to find elapsed time for ThreadPool
 
Similar Threads
how it works---join(),thread class.
ThreadPoolExecutor restart
stopping a runnable in ThreadPoolExecutor
Thread
Shutdown Threadpoolexecutor when queue is empty[SOLVED]