executorservice

java.util.concurrent

im trying to kick off a Runnable classes run method however i keep getting a NullPointerException, Im using WebSpheres commonj.workmanager to get an instance of executorService.this is the code im using. executorService.execute(new Runnable() { public void run() { System.out.println("Inside run ()method.."); ...

Can a java fixedThreadPool be used by multiple threads

I have a webservice that does multiple small calculations before returning the result. I want to use the ExecutorService provided by Executors.newFixedThreadPool() as a way to implement the Master - Worker pattern (ie. call invokeAll and let the thread wait for all results to finish). Ideally all webservice threads use the same executor ...

what would make a single task executor stop processing tasks?

I'm using a java.util.concurrent.ExecutorService that I obtained by calling Executors.newSingleThreadExecutor(). This ExecutorService can sometimes stop processing tasks, even though it has not been shutdown and continues to accept new tasks without throwing exceptions. Eventually, it builds up enough of a queue that my app shuts down wi...

invokeAll() is not willing to acept a Collection<Callable<T>>

Hey I fail to understand why this code won't compile ExecutorService executor = new ScheduledThreadPoolExecutor(threads); class DocFeeder implements Callable<Boolean> {....} ... List<DocFeeder> list = new LinkedList<DocFeeder>(); list.add(new DocFeeder(1)); ... executor.invokeAll(list); The error msg is: The method invokeAll(Col...

Searching for Generic Asynchronous Java Job Execution Framework / Library

I am looking for a generic asynchronous Java job execution framework that could handle Callables or Runnables. It would be similar to java.util.concurrent.ExecutorService, (and possibly wrap ExecutorService), but it would also have the following features: The ability to persist jobs to a database in case the application goes down while...

Porting code from using timers to scheduledexecutorservice

I am trying to port code from using java timers to using scheduledexecutorservice I have the following use case class A { public boolean execute() { try { Timer t = new Timer(); t.schedule (new ATimerTask(), period, delay); } catch (Exception e) { return false; ...

Java 5: java.util.concurrent.FutureTask - Semantics of cancel() and done()

I am currently hunting a nasty bug in a multi-threaded environment using FutureTasks and Executors. The basic idea is this to have a fixed number of threads execute individual FutureTasks that compute a result that is to be displayed in a a table (never mind the GUI aspect here). I have been looking at this for so long, I am beginning ...

Gridgain executor service

What are the advantages of using GridGain's GridExecutorService to execute jobs remotely vs using the @Gridify annotation? You can pass an instance of java.lang.concurrent.ExecutorService to your class and have no dependency on the grid framework but do you lose any functionality? ...

Help with java executors: wait for task termination.

I need to submit a number of task and then wait for them until all results are available. Each of them adds a String to a Vector (that is synchronized by default). Then I need to start a new task for each result in the Vector but I need to do this only when all the previous tasks have stopped doing their job. I want to use Java Executor...

Java Executors: how can I stop submitted tasks?

I have submitted a task using executors and I need it to stop after some time (e.g. 5 minutes). I have tried doing like this: for (Future<?> fut : e.invokeAll(tasks, 300, TimeUnit.SECONDS)) { try { fut.get(); } catch (CancellationException ex) { fut.cancel(true); tasks.clea...

Knowing when all threads complete and dealing with exceptions

Hi, I am using the Executor framework to kick off several threads using a threadpool i.e newFixedThreadPool. I use threadpool.submit(aThread) to submit jobs to be executed by the threadpool and this works fine however I need to determine when all the threads are complete so that I can continue with other processing. I looked at using F...

ScheduledExecutorService with variable delay

Suppose I have a task that is pulling elements from a java.util.concurrent.BlockingQueue and processing them. public void scheduleTask(int delay, TimeUnit timeUnit) { scheduledExecutorService.scheduleWithFixedDelay(new Task(queue), 0, delay, timeUnit); } How can I schedule / reschedule the task if the frequency can be changed dyna...

ExecutorService's surprising performance break-even point --- rules of thumb?

I'm trying to figure out how to correctly use Java's Executors. I realize submitting tasks to an ExecutorService has its own overhead. However, I'm surprised to see it is as high as it is. My program needs to process huge amount of data (stock market data) with as low latency as possible. Most of the calculations are fairly simple ar...

Removing all queued tasks of an ThreadPoolExecutor

Hi StackOverflow, i have this rather simple question about the ThreadPoolExecutor. I have the following situation: I have to consume objects from a queue, create the appropiate worker tasks for them and submit them to the ThreadPoolExecutor. This is quite simple. But within a shutdown scenario many workers may be queued to execution. Si...

What is the advantage of Executors over Threads in multithreaded application

I have seen several comments to the effect that Executors are better than Threads, but if you have a number of Threads communicating via bounded buffers (as in Flow-Based Programming) why would you use Executors when you have to use Threads anyway (with newCachedThreadPool (?)). Also, I use methods like isAlive(), interrupt() - how do I ...

Problems with use of "ExecutorCompletionService" with Callbable vs. Runnable

I have been working with the example code from the ExecutorCompletionService and put together the following example code. The code in solve() works as expected and prints 1 2 3 4 5 The code in solve2() doesn't print anything and in fact never exits. It doesn't matter whether ecs is constructed before or after submitting the jobs to th...

How can I report progress from a background task?

I have a long running task that is executing in the background on an ExecutorService thread pool. What are some best practices in terms of this task returning progress or intermediate results? Are there any libraries that provide this functionality? EDIT: To clarify, I'm talking about reporting progress to other code, not to the user....

Controlling Task execution order with ExecutorService

I have a process which delegates asynch tasks to a pool of threads. I need to ensure that certain tasks are executed in order. So for example Tasks arrive in order Tasks a1, b1, c1, d1 , e1, a2, a3, b2, f1 Tasks can be executed in any order except where there is a natural dependancy, so a1,a2,a3 must be processed in that order by ei...

Why doesn't the EDT shut down when all live threads are daemon?

The following code slides a card across the screen. When I shut down the main window, I expect the event dispatch thread to shut down as well, but it does not. Any ideas on why the ScheduledExecutorService thread prevents the EDT from shutting down? import java.awt.Graphics; import java.net.URL; import java.util.concurrent.Executors; im...

producer/consumer work queues

I'm wrestling with the best way to implement my processing pipeline. My producers feed work to a BlockingQueue. On the consumer side, I poll the queue, wrap what I get in a Runnable task, and submit it to an ExecutorService. while (!isStopping()) { String work = workQueue.poll(1000L, TimeUnit.MILLISECONDS); if (work == null) ...