Linked Questions
38 questions linked to/from ExecutorService, how to wait for all tasks to finish
36 votes
5 answers
35k views
Thread.join() equivalent in executor [duplicate]
I have a newbie question. I have this code: public class Main { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub ...
1 vote
2 answers
6k views
block until ExecutorService is done [duplicate]
Possible Duplicates: ExecutorService, how to wait for all tasks to finish Java ExecutorService: awaitTermination of all recursively created tasks Is there a way to block the current thread until ...
1 vote
4 answers
3k views
How do I print summary message after all threads (in a pool) complete? [duplicate]
I have a command line application. It runs a loop say 100 times and in the loop schedules a task using a thread. I am using ExecutorService so there are 4 threads running at any time. After the loop ...
0 votes
1 answer
118 views
Wait for executor for it's threads to finish by executor submit [duplicate]
UPDATE: I Fixed it with this code(Works only if you know the total tasks count, My case) int totalThreads = 0; int finishedThreads = 0; private void checkExecutorFinished() { if(finishedThreads =...
-2 votes
1 answer
86 views
Java Concurrent API's Lock not working as intended [duplicate]
I am trying to synchronize 2 threads using Java Concurrent's lock API. The code basically increments a counter to a certain number using 2 threads but the result i am getting is less than the said ...
0 votes
0 answers
120 views
Concurrency ExecutorService Counter from 1 to N [duplicate]
Sup! I am practicing & trying to cope with concurrency Now, I am attempting to count numbers from 1 to N (1000 in my example) using ExecutorService, but unluckily I am not able to receive the ...
0 votes
1 answer
70 views
How to shutdown the ThreadServiceExecutor where the number of threads is not initially known [duplicate]
I am in the process of writing a code where whenever a folder is encountered it is supposed to start a new thread. The code looks like, p ublic void diff(File x,File y){ ThreadPoolExecutor ...
469 votes
27 answers
457k views
How to wait for all threads to finish, using ExecutorService?
I need to execute some amount of tasks 4 at a time, something like this: ExecutorService taskExecutor = Executors.newFixedThreadPool(4); while(...) { taskExecutor.execute(new MyTask()); } //......
74 votes
7 answers
84k views
How to wait for all tasks in an ThreadPoolExecutor to finish without shutting down the Executor?
I can't use shutdown() and awaitTermination() because it is possible new tasks will be added to the ThreadPoolExecutor while it is waiting. So I'm looking for a way to wait until the ...
20 votes
9 answers
35k views
Return values from Java Threads
I have a Java Thread like the following: public class MyThread extends Thread { MyService service; String id; public MyThread(String id) { this.id = node; ...
16 votes
3 answers
52k views
Java: How to use Thread.join
I'm new to threads. How can I get t.join to work, whereby the thread calling it waits until t is done executing? This code would just freeze the program, because the thread is waiting for itself to ...
7 votes
4 answers
11k views
invokeAll() is not willing to accept a Collection<Callable<T>>
I fail to understand why this code won't compile ExecutorService executor = new ScheduledThreadPoolExecutor(threads); class DocFeeder implements Callable<Boolean> {....} ... List<...
9 votes
4 answers
11k views
How to know when a CompletionService is finished delivering results?
I want to use a CompletionService to process the results from a series of threads as they are completed. I have the service in a loop to take the Future objects it provides as they become available, ...
6 votes
3 answers
13k views
How to implement an ExecutorService to execute batches of tasks
I am looking for a way to execute batches of tasks in java. The idea is to have an ExecutorService based on a thread pool that will allow me to spread a set of Callable among different threads from a ...
5 votes
4 answers
9k views
When the executorService.shutdown(); should be called
We have a service method GetDataParallel( ) which maybe called by many clients currently, and we use the ExecutorService to called the MyCallable inside it. However I found unless I called the ...