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

15 30 50 per page