List of usage examples for java.util.concurrent ExecutorService isShutdown
boolean isShutdown();
From source file:com.taveloper.http.test.PwTest.java
/** * @param args the command line arguments */// w w w . j a va2 s. co m public static void main(String[] args) throws IOException, InterruptedException { ExecutorService es = Executors.newFixedThreadPool(1); // ? try { for (int i = 0; i < a.length; i++) { String s1 = a[i]; for (int j = 0; j < a.length; j++) { String s2 = a[j]; Pw pw = new Pw(s1 + s2); es.submit(pw); } } } catch (Exception e) { System.out.println(e.toString()); } if (es.isShutdown()) { } else { Thread.sleep(1000); } }
From source file:Main.java
public static final void shutdownAndAwaitTermination(ExecutorService executorService) { if (executorService.isShutdown()) { return;//w ww .j a v a2s . com } executorService.shutdown(); try { if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) { executorService.shutdownNow(); } } catch (InterruptedException ie) { executorService.shutdownNow(); Thread.currentThread().interrupt(); } executorService.shutdownNow(); }
From source file:Main.java
public static void printStatus(Object o) { if (o instanceof Thread) { Thread t = (Thread) o; System.out.println("Thread " + t.getName() + " " + t.getState()); } else if (o instanceof ExecutorService) { ExecutorService e = (ExecutorService) o; System.out.println("Executor " + e.isShutdown() + " " + e.isTerminated()); }//from w ww . ja v a 2 s. c om }
From source file:Main.java
public static boolean isShutDown(ExecutorService executorService) { return (executorService == null || executorService.isShutdown()); }
From source file:Main.java
public static final void shutdownAndAwaitTermination(ExecutorService executorService, long timeout, TimeUnit timeUnit) {/*from ww w . j ava 2 s .co m*/ if (executorService.isShutdown()) { return; } executorService.shutdown(); try { if (!executorService.awaitTermination(timeout, timeUnit)) { executorService.shutdownNow(); } } catch (InterruptedException ie) { executorService.shutdownNow(); Thread.currentThread().interrupt(); } executorService.shutdownNow(); }
From source file:org.jactr.core.concurrent.ExecutorServices.java
/** * shutdown and wait for the shutdown of all the executors that are currently * installed. if millisecondsToWait is 0, it will wait indefinitely *///w ww . j a va 2 s . co m static public void shutdown(long millisecondsToWait) { synchronized (_executors) { _isShuttingDown = true; } Collection<String> executorNames = new ArrayList<String>(); getExecutorNames(executorNames); /* * issue shutdown */ for (String name : executorNames) { ExecutorService executor = getExecutor(name); if (executor != null && !executor.isShutdown()) executor.shutdown(); } /* * and wait */ long interval = 500; long abortAt = System.currentTimeMillis() + millisecondsToWait; if (millisecondsToWait == 0) abortAt = Long.MAX_VALUE; while (abortAt > System.currentTimeMillis() && executorNames.size() != 0) { for (String name : executorNames) { ExecutorService executor = getExecutor(name); if (executor != null) try { if (executor.awaitTermination(interval, TimeUnit.MILLISECONDS)) removeExecutor(name); else if (LOGGER.isDebugEnabled()) LOGGER.debug(name + " did not terminate after " + interval + "ms"); } catch (Exception e) { if (LOGGER.isWarnEnabled()) LOGGER.warn("Failed to terminate " + name, e); removeExecutor(name); } } /* * get the current names again.. */ executorNames.clear(); getExecutorNames(executorNames); } if (executorNames.size() != 0) { if (LOGGER.isWarnEnabled()) LOGGER.warn("Forcing unresponsive executors to terminate " + executorNames + " after " + millisecondsToWait + "ms"); for (String name : executorNames) { ExecutorService executor = getExecutor(name); if (executor != null) executor.shutdownNow(); } } synchronized (_executors) { _executors.clear(); _isShuttingDown = false; } }
From source file:org.apache.phoenix.util.PhoenixMRJobUtil.java
public static void shutdown(ExecutorService pool) throws InterruptedException { pool.shutdown();/*from w w w. j av a2 s . c o m*/ LOG.debug("Shutdown called"); pool.awaitTermination(200, TimeUnit.MILLISECONDS); LOG.debug("Await termination called to wait for 200 msec"); if (!pool.isShutdown()) { pool.shutdownNow(); LOG.debug("Await termination called to wait for 200 msec"); pool.awaitTermination(100, TimeUnit.MILLISECONDS); } if (!pool.isShutdown()) { LOG.warn("Pool did not shutdown"); } }
From source file:org.geoserver.wms.WMSLifecycleHandler.java
/** * Suddenly shuts down the Animator Executor Service *//*from w ww. j a v a 2 s. com*/ private void shutdownAnimatorExecutorService() { final ExecutorService animatorExecutorService = this.wmsConfig.getAnimatorExecutorService(); if (animatorExecutorService != null && !animatorExecutorService.isShutdown()) { animatorExecutorService.shutdownNow(); } }
From source file:com.brienwheeler.lib.concurrent.ExecutorsTest.java
@Test public void testFinalize() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { NamedThreadFactory threadFactory = new NamedThreadFactory(THREAD_FACTORY_NAME); ExecutorService executor = Executors.newSingleThreadExecutor(threadFactory); Assert.assertFalse(executor.isShutdown()); Method finalize = executor.getClass().getDeclaredMethod("finalize"); finalize.setAccessible(true);//from w ww.jav a 2 s. c o m finalize.invoke(executor); Assert.assertTrue(executor.isShutdown()); }
From source file:com.brienwheeler.lib.concurrent.ExecutorsTest.java
@Test public void testNewSingleThreadExecutorShutdownClean() throws InterruptedException { NamedThreadFactory threadFactory = new NamedThreadFactory(THREAD_FACTORY_NAME); ExecutorService executor = Executors.newSingleThreadExecutor(threadFactory); Assert.assertFalse(executor.isShutdown()); Assert.assertFalse(executor.isTerminated()); executor.execute(new NullRunnable()); executor.shutdown();//from w w w .j a v a 2s .c om Assert.assertTrue(executor.isShutdown()); executor.awaitTermination(10, TimeUnit.MILLISECONDS); Assert.assertTrue(executor.isTerminated()); }