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 ...
4 votes
3 answers
15k views
Java - ExecutorService has a maximum size
Is there any way to go through a huge database and apply some jobs in parallel for bench of entries? I tried with ExecutorService, but we have to shutdown() in order to know the pool size... So my ...
15 votes
2 answers
2k views
Android equivalent of iOS GCD dispatch_group API
I come from an iOS background and I'm new to Android. Is there an efficient and fast way to make the same network API call but with different parameters each time where the parameters are stored in ...
9 votes
1 answer
5k views
Waiting for callback for multiple futures
Recently I've delved into a little bit of work using an API. The API uses the Unirest http library to simplify the work of receiving from the web. Naturally, since the data is called from the API ...
6 votes
3 answers
8k views
Correct way to submit to and wait for termination of an ExecutorService
I am learning how to use thread pools in Java using ExecutorService, here is an example I am working on: public class Example { static class WorkerThread implements Runnable { private ...
4 votes
1 answer
6k views
JAVA Multi-Threading, Memory Leak, Garbage Collector
I'm a bit of a novice when it comes to JAVA applications, but have been involved in developing a fairly complex JAVA(8) app that requires multi-threading. Myself and another developer have kept ...
1 vote
5 answers
3k views
How can I tell that threads in ThreadPoolExecutor are done?
I am writing code where I need to make sure that no threads are currently running in a thread pool before I commit results (to avoid losing data I should have put in the commit). For that, I'm using: ...
3 votes
1 answer
6k views
how to check if all threads in executor service is done
I'm trying to calculate some metrics, once all the threads in the myclass are done, the job is done for the thread once i reach the timeout scenario, which i able to hit for every thread. Now in the ...
4 votes
2 answers
3k views
Do I need to synchronize on the result of an invokeAll call?
I am enhancing an existing algorithm that consists of multiple independent steps to use concurrent tasks. Each of the tasks will create multiple objects to hold its results. In the end, I would like ...
2 votes
5 answers
2k views
how to deal with multiple worker threads that may create new work items
I have a queue that contains work items and I want to have multiple threads work in parallel on those items. When a work item is processed it may result in new work items. The problem I have is that I ...
2 votes
4 answers
1k views
ExecutorService never stops without Exceptions
I adopted a the concurrency strategy from this post. However mine looks like this: ExecutorService executorService = Executors.newFixedThreadPool(NUMBER_OF_CREATE_KNOWLEDGE_THREADS); List<Callable&...
2 votes
3 answers
199 views
ExecutorService: Better Thread-flow Regulation
I have a question based on the ExecutorService Thread flow regulation: I would like to .submit() multiple threads for executon where I would like some threads to wait until specific previous Threads ...
2 votes
2 answers
251 views
Multithreaded approach using java Executor interface
I am trying to implement the multithreaded approach using executor interface where i have produced multiple threads in main class class Main { private static final int NTHREADS = 10; public ...
1 vote
2 answers
227 views
Java multi-thread does not update value in unit test
I have a Spring service, and I want to test its correctness for concurrent thread. @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class SerialNumberServiceTest { @Autowired private ...
0 votes
2 answers
680 views
Enforce executorService.awaitTermination while using CompletionService
I am trying to submit multiple tasks and obtain the results as and when it is available. However, after the end of the loop, I have to enforce that all the tasks complete within specified amount of ...
1 vote
1 answer
416 views
Multithreading with AtomicInteger and ExecutorService not working
public class SynchroExample { public final AtomicInteger integer = new AtomicInteger(0); private ExecutorService service = Executors.newFixedThreadPool(100); public void syn() { for (...
0 votes
1 answer
412 views
Will thread execution continues when waiting for Future of one thread
I want to know that when a program waits for Future object of one thread, will other threads continue their execution. I have tried the below sample, it seems when my program is waiting for one ...
0 votes
1 answer
480 views
How to still manage parallelization using Future.get?
I want to run the threads in parallel and handle the exception if any thread fails while running. But, when I am using the future.get method, I am unable to maintain parallel execution. How can this ...
2 votes
3 answers
200 views
Simultaneously processing in one Servlet
I have a Servlet which recieves a request, has to process 5 tasks (Grab data Form external Servers) and send all the data back to the client ordered. How to process the 5 Task simultaneously and ...
0 votes
1 answer
241 views
Having problemns using threads to copy emails to folder in javamail
I´m having problem to copy some emails to other folder using threads, my problem is, the code don´t wait to finish the job. I want to move the messages by threads to accelaret the job, but I need to ...
1 vote
1 answer
85 views
Why do these Callables never get done?
I have a code snippet where a loop submits Callable and then checks if these are done and if so print out their Values ArrayList<Future<ArrayList<String>>> controllList = new ...
0 votes
2 answers
100 views
Awaiting pool to finish threads
StopWatch sw = new StopWatch(); sw.start(); ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS); for (int i = 0; i < MYTHREADS; i++) { Runnable worker = new ...
0 votes
3 answers
95 views
How to start a new Activity after several async tasks had finished
I have a big Problem: I want to start a new Activity after several Async-Tasks had finished. My problem is that the Async-Tasks are dynamically started. Some time I have only one Async-Task, some ...
0 votes
0 answers
84 views
Java Callable Attempts to Complete Prematurely
I have a method that is called with multi threading and runs to around 99% completion. At this point it runs the next method which needs the first method to of finished running before attempting as it ...