List of usage examples for java.util.concurrent ExecutorService awaitTermination
boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException;
From source file:Main.java
static void awaitTermination(ExecutorService threadPool) { threadPool.shutdown();//from w w w . j a v a2s . co m try { threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:Main.java
public static void stop(ExecutorService executor) { try {/*from w ww.j a v a 2 s . c om*/ executor.shutdown(); executor.awaitTermination(60, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:Main.java
public static void stop(ExecutorService executor) { try {/* w w w . jav a 2s. com*/ executor.shutdown(); executor.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { System.err.println("termination interrupted"); } finally { if (!executor.isTerminated()) { System.err.println("killing non-finished tasks"); } executor.shutdownNow(); } }
From source file:Main.java
public static void stop(ExecutorService executor) { try {//from www . j a va2s . com executor.shutdown(); executor.awaitTermination(60, TimeUnit.SECONDS); } catch (InterruptedException e) { System.err.println("termination interrupted"); } finally { if (!executor.isTerminated()) { System.err.println("killing non-finished tasks"); } executor.shutdownNow(); } }
From source file:Main.java
public static void stop(ExecutorService executor) { try {/* www . j ava 2 s . c o m*/ executor.shutdown(); executor.awaitTermination(60, TimeUnit.SECONDS); } catch (InterruptedException e) { System.err.println("termination interrupted"); } finally { if (!executor.isTerminated()) { System.out.println("killing non-finished tasks"); } executor.shutdownNow(); } }
From source file:Main.java
public static void shutdownAndWait(ExecutorService threadPool, long timeout, TimeUnit unit) { threadPool.shutdown();/*from w w w. ja v a 2 s. c om*/ try { threadPool.awaitTermination(timeout, unit); } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:ReplaceWorker.java
private static void awaitTermination(ExecutorService threadPool) { try {// w w w . j a v a 2s . c om threadPool.shutdown(); boolean awaitTermination = threadPool.awaitTermination(1, TimeUnit.SECONDS); System.out.println("terminted successfull: " + awaitTermination); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void normalShutdown(ExecutorService pool, int timeout, TimeUnit timeUnit) { try {//from w ww. j a v a2 s.c om pool.shutdownNow(); if (!pool.awaitTermination(timeout, timeUnit)) { System.err.println("Pool did not terminated"); } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } }
From source file:Main.java
/** * Normal shutdown./*from ww w .ja va 2 s. c om*/ * * @param pool the pool * @param timeout the timeout * @param timeUnit the time unit */ public static void normalShutdown(ExecutorService pool, int timeout, TimeUnit timeUnit) { try { pool.shutdownNow(); if (!pool.awaitTermination(timeout, timeUnit)) { System.err.println("Pool did not terminate"); } } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } }
From source file:Main.java
/** * close the thread pool safely.//from w ww . j a va2s . c o m * @param pool */ public static void safeClose(ExecutorService pool) { if (pool != null) { pool.shutdown(); try { if (!pool.awaitTermination(60, TimeUnit.SECONDS)) { pool.shutdownNow(); } } catch (InterruptedException ex) { //ignore the ex } } }