/** * Stops logging clients. This is a blocking call. */ public void stop() { service.shutdown(); if (!service.isTerminated()) { service.shutdownNow(); try { service.awaitTermination(1000, TimeUnit.SECONDS); } catch (InterruptedException e) { LOGGER.error("exception awaiting termination", e); } } LOGGER.info("Logging clients stopped"); }
@Override public void shutdown() { if (null != fileWriteExecutor) { fileWriteExecutor.shutdown(); stopping = true; int retry = 0; while (!fileWriteExecutor.isTerminated() && retry < MAX_SHUTDOWN_RETRY) { ++retry; try { Thread.sleep(SHUTDOWN_CHECK_INTERNAL); } catch (InterruptedException exx) {} } if (retry >= MAX_SHUTDOWN_RETRY) { fileWriteExecutor.shutdownNow(); } } }
/** * Bean destroy-method. Call before bean destroying. */ public void destroy() { if (sendPool != null) { sendPool.shutdown(); try { while (sendPool.isTerminated() == false) { sendPool.awaitTermination(sendTimeout, TimeUnit.SECONDS); } } catch (InterruptedException ex) { LOG.warn("shutdown interrupted on {}", sendPool, ex); } } }
/** * Shutdown now the given executor service aggressively. * * @param executorService the executor service to shutdown now * @return list of tasks that never commenced execution * @see java.util.concurrent.ExecutorService#shutdownNow() */ public static List<Runnable> shutdownNow(ExecutorService executorService) { List<Runnable> answer = null; if (!executorService.isShutdown()) { LOG.debug("Forcing shutdown of ExecutorService: {}", executorService); answer = executorService.shutdownNow(); if (LOG.isTraceEnabled()) { LOG.trace("Shutdown of ExecutorService: {} is shutdown: {} and terminated: {}.", new Object[]{executorService, executorService.isShutdown(), executorService.isTerminated()}); } } return answer; }
final ExecutorService pool = Executors.newFixedThreadPool(2); final CompletionService<String> service = new ExecutorCompletionService<String>(pool); final List<? extends Callable<String>> callables = Arrays.asList( new SleepingCallable("slow", 5000), new SleepingCallable("quick", 500)); for (final Callable<String> callable : callables) { service.submit(callable); } pool.shutdown(); try { while (!pool.isTerminated()) { final Future<String> future = service.take(); System.out.println(future.get()); } } catch (ExecutionException | InterruptedException ex) { }
@Override public void stop() { // fix bug #968,对于pool与 workerPool.halt(); simpleParserStage.halt(); sinkStoreStage.halt(); try { parserExecutor.shutdownNow(); while (!parserExecutor.awaitTermination(1, TimeUnit.SECONDS)) { if (parserExecutor.isShutdown() || parserExecutor.isTerminated()) { break; } parserExecutor.shutdownNow(); } } catch (Throwable e) { // ignore } try { stageExecutor.shutdownNow(); while (!stageExecutor.awaitTermination(1, TimeUnit.SECONDS)) { if (stageExecutor.isShutdown() || stageExecutor.isTerminated()) { break; } stageExecutor.shutdownNow(); } } catch (Throwable e) { // ignore } super.stop(); }
public void shutdown() { if (started.compareAndSet(true, false)) { LOG.debug("Shutting down webcam processor"); runner.shutdown(); LOG.debug("Awaiting tasks termination"); while (runner.isTerminated()) { try { runner.awaitTermination(100, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { return; } runner.shutdownNow(); } LOG.debug("All tasks has been terminated"); } }
public void shutdown() { LOG.info("Shutting down goal optimizer."); _shutdown = true; _proposalPrecomputingExecutor.shutdown(); try { _proposalPrecomputingExecutor.awaitTermination(30000L, TimeUnit.MILLISECONDS); if (!_proposalPrecomputingExecutor.isTerminated()) { LOG.warn("The goal optimizer failed to shutdown in 30000 ms."); } } catch (InterruptedException e) { LOG.warn("Interrupted while waiting for goal optimizer to shutdown."); } LOG.info("Goal optimizer shutdown completed."); }
final Runnable stuffToDo = new Thread() { @Override public void run() { /* Do stuff here. */ } }; final ExecutorService executor = Executors.newSingleThreadExecutor(); final Future future = executor.submit(stuffToDo); executor.shutdown(); // This does not cancel the already-scheduled task. try { future.get(5, TimeUnit.MINUTES); } catch (InterruptedException ie) { /* Handle the interruption. Or ignore it. */ } catch (ExecutionException ee) { /* Handle the error. Or ignore it. */ } catch (TimeoutException te) { /* Handle the timeout. Or ignore it. */ } if (!executor.isTerminated()) executor.shutdownNow(); // If you want to stop the code that hasn't finished.
if (!executor.isTerminated()) { executor.shutdownNow();
/** * Run the application's maps using a thread pool. */ @Override public void run(Context context) throws IOException, InterruptedException { outer = context; int numberOfThreads = getNumberOfThreads(context); mapClass = getMapperClass(context); if (LOG.isDebugEnabled()) { LOG.debug("Configuring multithread runner to use " + numberOfThreads + " threads"); } executor = Executors.newFixedThreadPool(numberOfThreads); for(int i=0; i < numberOfThreads; ++i) { MapRunner thread = new MapRunner(context); executor.execute(thread); } executor.shutdown(); while (!executor.isTerminated()) { // wait till all the threads are done Thread.sleep(1000); } }
task.running = false; pool.shutdownNow(); pool.awaitTermination(5000, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { LOGGER.error(e.getMessage(), e); if (!pool.isTerminated()) { LOGGER.error("Timed out when shutdown sessionizer thread pool"); if (timer.isTerminated() && pool.isTerminated()) { break;
long halfTimeoutNanos = unit.toNanos(timeout) / 2; service.shutdown(); try { if (!service.awaitTermination(halfTimeoutNanos, TimeUnit.NANOSECONDS)) { service.shutdownNow(); service.awaitTermination(halfTimeoutNanos, TimeUnit.NANOSECONDS); service.shutdownNow(); return service.isTerminated();
void stopExecutor(ExecutorService executor) { if (executor == null) { return; } executor.shutdown(); final int secToWait = Integer .getInteger(DistributionConfig.GEMFIRE_PREFIX + "prrecovery-close-timeout", 120).intValue(); try { executor.awaitTermination(secToWait, TimeUnit.SECONDS); } catch (InterruptedException x) { Thread.currentThread().interrupt(); logger.debug("Failed in interrupting the Resource Manager Thread due to interrupt"); } if (!executor.isTerminated()) { logger.warn("Failed to stop resource manager threads in {} seconds", secToWait); } }
private void closeSessionMonitor() { if ( sessionMonitor != null && !sessionMonitor.isShutdown() ) { try { getLogChannel().logDebug( "Shutting down the Session Monitor." ); sessionMonitor.shutdown(); } finally { if ( !sessionMonitor.isTerminated() ) { sessionMonitor.shutdownNow(); } getLogChannel().logDebug( "Session Monitor shutdown." ); } } }
if (executorService != null && !executorService.isTerminated()) { for (TSocketWrapper socket : new ArrayList<>(openedSockets)) { if (socket.getSocket() != null && !socket.getSocket().isClosed()) { executorService.shutdownNow();
@After public void cleanup() { if ( executorService != null && !executorService.isTerminated() ) { executorService.shutdown(); } }
private void afterLoad(ExecutorService es) throws InterruptedException { es.awaitTermination(5, TimeUnit.MINUTES); if (es.isTerminated()) { for (DataLoader l : loaders) { l.allDataLoaded(); } } else { log.error("The following data loaders did not complete in time: "); for(Runnable r : es.shutdownNow()) { log.error("The following data loaders did not complete in time: {}", r); } } }
/** * Shutdown graciously the executor service */ void stop() { LOG.info("Shutting down interceptor thread pool..."); executor.shutdown(); try { LOG.info("Waiting for thread pool tasks to terminate..."); executor.awaitTermination(10L, TimeUnit.SECONDS); } catch (InterruptedException e) { } if (!executor.isTerminated()) { LOG.warn("Forcing shutdown of interceptor thread pool..."); executor.shutdownNow(); } LOG.info("interceptors stopped"); }
public void testShutdownAndAwaitTermination_immediateShutdownInternal() throws Exception { ExecutorService service = mock(ExecutorService.class); when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS)).thenReturn(true); when(service.isTerminated()).thenReturn(true); assertTrue(shutdownAndAwaitTermination(service, 1L, SECONDS)); verify(service).shutdown(); verify(service).awaitTermination(HALF_SECOND_NANOS, NANOSECONDS); }