I have a ThreadPoolExecutor , and I'm sending him a job.
private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
This code sends the Runnable to ThreadPoolExecutor .
protected void waitAndSweep(final String symbol) { runnable = new Runnable() { public void run() { } }; try { Future<?> self = threadPoolExecutor.submit(runnable); futures.add(self); } catch (RejectedExecutionException re) { } catch (Exception e) { logEvent(StrategyEntry.ERROR, "waitAndSweep", symbol, "Exception caught...", e); } }
The following code stops the task.
protected synchronized void stop(StrategyEntry entry) throws Exception { for (Object future : futures) { ((Future<?>) future).cancel(true); } futures.clear(); threadPoolExecutor.shutdown(); }
The problem here is: when I try to stop the task, I get the following exception:
java.util.concurrent.FutureTask@3a475611 rejected from java.util.concurrent.ThreadPoolExecutor@216393fb [Finished, pool size = 0, active threads = 0, tasks with posts = 0, completed jobs = 1]
Mmpgm source share