/** * @param c Closure to run. */ void runInWorkerThread(Runnable c) { IgniteThreadPoolExecutor pool; synchronized (stateMux) { if (connState == ConnectionState.STOPPED) { LT.warn(log, "Do not run closure, node is stopped."); return; } if (utilityPool == null) { utilityPool = new IgniteThreadPoolExecutor("zk-discovery-pool", igniteInstanceName, 0, 1, 2000, new LinkedBlockingQueue<Runnable>()); } pool = utilityPool; } pool.submit(c); }
/** * @throws ExecutionException If failed. */ @Test public void testGridThreadPoolExecutor() throws Exception { IgniteThreadPoolExecutor exec = new IgniteThreadPoolExecutor("", "", 1, 1, 0, new LinkedBlockingQueue<Runnable>()); exec.submit(new InterruptingRunnable()).get(); Future<Boolean> fut = exec.submit(new IsInterruptedAssertionCallable()); assert !fut.get() : "Expecting the executor to reset the interrupted flag when reinvoking the thread"; exec.shutdown(); assert exec.awaitTermination(30, SECONDS); }
/** * @throws ExecutionException If failed. */ @Test public void testGridThreadPoolExecutorRejection() throws Exception { IgniteThreadPoolExecutor exec = new IgniteThreadPoolExecutor("", "", 1, 1, 0, new LinkedBlockingQueue<Runnable>()); for (int i = 0; i < 10; i++) exec.submit(new TestRunnable()); exec.shutdown(); assert exec.awaitTermination(30, SECONDS); }