logo       

Re: How do I wait for the thread from the ThreadPool to finish?: msg#00034

java.jsr.166-concurrency

Subject: Re: How do I wait for the thread from the ThreadPool to finish?

Minnie Haridasa wrote:


Hi.


I am trying to use the PooledExecutor to create a thread pool. Once I create my runnable task that needs to be executed, how does the calling thread wait for the thread in the pool to finish, especially since I do not have the handle to the thread that is executing the task.


threadPool.execute(task);

// At this point the calling thread needs to wait for the task to complete.



Use the submit method (in ExecutorService interface):

Future f = executor.submit(runnable, null);

then you can wait using f.get().


(You can also explicitly wrap your runnable into callable before submitting: Executors.callable(runnable)).

Regards,
Dawid


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise