samir ware wrote:Hey Macro
Thanks a lot for the reply. You got me right. Yes...I do want to know when exactly all the threads in the pool are done with their execution. API that you have suggested is helpfull though I am quiet unsure about how much time will the thread take to finish their jobs. It may be 5 minutes, may be 1 hour
Marco Ehrentreich wrote:
Perhaps I should note that it is in general a good idea to define reasonable timeouts in situations like this
samir ware wrote:Hello Ranchers
Though is there any way by which I will get to know that now all the threads are done with the working and all of them came back in to the thread pool . I need to catch this event as I want to perform some operation when threads gets done with their processing .
Nomaan Butt wrote:
samir ware wrote:Hello Ranchers
Though is there any way by which I will get to know that now all the threads are done with the working and all of them came back in to the thread pool . I need to catch this event as I want to perform some operation when threads gets done with their processing .
you can achive this using the isDone() method of Future interface, put all the tasks(Callable) in an ArrayList and pass them to the below method
then call the isDone() method on the retuned list of Futures to find if they have finished.
isDone() will return true if the task has finished.
Future interface is used to find the states of the current threads in pool.
Jeff Verdegan wrote:
Actually, the Future is tied to your tasks, not to the threads that execute them. And I would argue that for this reason, it's probably a more appropriate approach than the other one suggested earlier.
@OP: If you're using a thread pool in the first place, it means you have deliberately chosen to separate your tasks from the threads that execute them, and it seems more likely that you would care about when those tasks are done, rather than caring about the threads. If you really do want to know when the threads are all done, it seems simpler to just manage the threads yourself, and call their join() methods.
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|