/** * Returns <code>true</code> if the given pool was terminated successfully. If the termination timed out, * the service is <code>null</code> this method will return <code>false</code>. */ public static boolean terminate(ThreadPool pool, long timeout, TimeUnit timeUnit) { if (pool != null) { try { pool.shutdown(); if (awaitTermination(pool, timeout, timeUnit)) { return true; } // last resort pool.shutdownNow(); return awaitTermination(pool, timeout, timeUnit); } finally { IOUtils.closeWhileHandlingException(pool); } } return false; }
@After @Override public void tearDown() throws Exception { super.tearDown(); threadPool.shutdown(); }
toClose.add(() -> injector.getInstance(ThreadPool.class).shutdown()); toClose.add(() -> { try {
/** * Returns <code>true</code> if the given pool was terminated successfully. If the termination timed out, * the service is <code>null</code> this method will return <code>false</code>. */ public static boolean terminate(ThreadPool pool, long timeout, TimeUnit timeUnit) { if (pool != null) { pool.shutdown(); try { if (pool.awaitTermination(timeout, timeUnit)) { return true; } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } // last resort pool.shutdownNow(); } return false; }
/** * Returns <code>true</code> if the given pool was terminated successfully. If the termination timed out, * the service is <code>null</code> this method will return <code>false</code>. */ public static boolean terminate(ThreadPool pool, long timeout, TimeUnit timeUnit) { if (pool != null) { try { pool.shutdown(); if (awaitTermination(pool, timeout, timeUnit)) return true; // last resort pool.shutdownNow(); return awaitTermination(pool, timeout, timeUnit); } finally { IOUtils.closeWhileHandlingException(pool); } } return false; }
/** * Returns <code>true</code> if the given pool was terminated successfully. If the termination timed out, * the service is <code>null</code> this method will return <code>false</code>. */ public static boolean terminate(ThreadPool pool, long timeout, TimeUnit timeUnit) { if (pool != null) { try { pool.shutdown(); if (awaitTermination(pool, timeout, timeUnit)) { return true; } // last resort pool.shutdownNow(); return awaitTermination(pool, timeout, timeUnit); } finally { IOUtils.closeWhileHandlingException(pool); } } return false; }
/** * Returns <code>true</code> if the given pool was terminated successfully. If the termination timed out, * the service is <code>null</code> this method will return <code>false</code>. */ public static boolean terminate(ThreadPool pool, long timeout, TimeUnit timeUnit) { if (pool != null) { try { pool.shutdown(); if (awaitTermination(pool, timeout, timeUnit)) { return true; } // last resort pool.shutdownNow(); return awaitTermination(pool, timeout, timeUnit); } finally { IOUtils.closeWhileHandlingException(pool); } } return false; }
toClose.add(() -> injector.getInstance(ThreadPool.class).shutdown()); toClose.add(() -> { try {
toClose.add(() -> injector.getInstance(ThreadPool.class).shutdown()); toClose.add(() -> { try {
toClose.add(() -> injector.getInstance(ThreadPool.class).shutdown()); toClose.add(() -> { try {
injector.getInstance(ThreadPool.class).shutdown(); try { injector.getInstance(ThreadPool.class).awaitTermination(10, TimeUnit.SECONDS);
injector.getInstance(ThreadPool.class).shutdown(); try { injector.getInstance(ThreadPool.class).awaitTermination(10, TimeUnit.SECONDS);
injector.getInstance(ThreadPool.class).shutdown(); try { injector.getInstance(ThreadPool.class).awaitTermination(10, TimeUnit.SECONDS);