Linked Questions

36 votes
5 answers
35k views

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 ...
Mario Stoilov's user avatar
1 vote
2 answers
6k views

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 ...
fredoverflow's user avatar
1 vote
4 answers
3k views

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 ...
user373201's user avatar
  • 11.5k
0 votes
1 answer
118 views

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 =...
Ahmad B's user avatar
  • 29
-2 votes
1 answer
86 views

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 ...
wut's user avatar
  • 31
0 votes
0 answers
120 views

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 ...
binocla's user avatar
  • 33
0 votes
1 answer
70 views

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 ...
Debdipta Halder's user avatar
469 votes
27 answers
457k views

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()); } //......
serg's user avatar
  • 112k
74 votes
7 answers
84k views

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 ...
cottonBallPaws's user avatar
20 votes
9 answers
35k views

I have a Java Thread like the following: public class MyThread extends Thread { MyService service; String id; public MyThread(String id) { this.id = node; ...
Langali's user avatar
  • 3,217
16 votes
3 answers
52k views

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 ...
Nick Heiner's user avatar
7 votes
4 answers
11k views

I fail to understand why this code won't compile ExecutorService executor = new ScheduledThreadPoolExecutor(threads); class DocFeeder implements Callable<Boolean> {....} ... List<...
Yossale's user avatar
  • 14.4k
9 votes
4 answers
11k views

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, ...
Ed Beaty's user avatar
  • 477
6 votes
3 answers
13k views

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 ...
Victor P.'s user avatar
  • 675
5 votes
4 answers
9k views

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 ...
Jason's user avatar
  • 1,199
4 votes
3 answers
15k views

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 ...
Bast's user avatar
  • 671
15 votes
2 answers
2k views

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 ...
user299648's user avatar
  • 2,819
9 votes
1 answer
5k views

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 ...
John Mace's user avatar
  • 103
6 votes
3 answers
8k views

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 ...
syntagma's user avatar
  • 24.6k
4 votes
1 answer
6k views

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 ...
Simon Nicholls's user avatar
1 vote
5 answers
3k views

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: ...
Clovis's user avatar
  • 4,483
3 votes
1 answer
6k views

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 ...
amateur's user avatar
  • 961
4 votes
2 answers
3k views

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 ...
janko's user avatar
  • 4,213
2 votes
5 answers
2k views

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 ...
Stefan's user avatar
  • 675
2 votes
4 answers
1k views

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&...
Daniel Gerber's user avatar
2 votes
3 answers
199 views

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 ...
Mora Misina's user avatar
2 votes
2 answers
251 views

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 ...
Nishit Jain's user avatar
  • 1,589
1 vote
2 answers
227 views

I have a Spring service, and I want to test its correctness for concurrent thread. @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class SerialNumberServiceTest { @Autowired private ...
BurnetZhong's user avatar
0 votes
2 answers
680 views

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 ...
dmachop's user avatar
  • 894
1 vote
1 answer
416 views

public class SynchroExample { public final AtomicInteger integer = new AtomicInteger(0); private ExecutorService service = Executors.newFixedThreadPool(100); public void syn() { for (...
Harshil Garg's user avatar
0 votes
1 answer
412 views

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 ...
Antony Vimal Raj's user avatar
0 votes
1 answer
480 views

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 ...
Rockan's user avatar
  • 161
2 votes
3 answers
200 views

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 ...
user3876178's user avatar
0 votes
1 answer
241 views

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 ...
Diego Macario's user avatar
1 vote
1 answer
85 views

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 ...
flxh's user avatar
  • 565
0 votes
2 answers
100 views

StopWatch sw = new StopWatch(); sw.start(); ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS); for (int i = 0; i < MYTHREADS; i++) { Runnable worker = new ...
DarthVader's user avatar
  • 55.6k
0 votes
3 answers
95 views

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 ...
thatmarcel's user avatar
0 votes
0 answers
84 views

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 ...
PondleDondle's user avatar