/** * Stops the timer, cancelling all tasks * * @throws InterruptedException if interrupted while waiting for thread to return */ public void stop() { stopRunner(); List<Runnable> remaining_tasks = pool.shutdownNow(); for (Runnable task : remaining_tasks) { if (task instanceof Future) { Future future = (Future) task; future.cancel(true); } } pool.getQueue().clear(); try { pool.awaitTermination(Global.THREADPOOL_SHUTDOWN_WAIT_TIME, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { } }
static void oneRun(BlockingQueue<Runnable> q, int nThreads, int iters, boolean print) throws Exception { ThreadPoolExecutor pool = new ThreadPoolExecutor(nThreads + 1, Integer.MAX_VALUE, 1L, TimeUnit.SECONDS, q); CountDownLatch done = new CountDownLatch(iters); remaining.set(nThreads - 1); pool.prestartAllCoreThreads(); Task t = new Task(pool, done); long start = System.nanoTime(); pool.execute(t); done.await(); long time = System.nanoTime() - start; if (print) System.out.println("\t: " + LoopHelpers.rightJustify(time / iters) + " ns per task"); q.clear(); Thread.sleep(100); pool.shutdown(); Thread.sleep(100); pool.shutdownNow(); }
@Override public synchronized void close() throws SecurityException { if (pool.isShutdown()) { return; } try { // first, anything in the retry queue should be tried one last time and then we give up on it allowRetry = false; for (LogglySample sample : retryQueue) { pool.submit(sample); } retryQueue.clear(); System.out.println( "Shutting down Loggly handler - waiting 90 seconds for " + pool.getQueue().size() + " logs to finish"); pool.shutdown(); try { boolean result = pool.awaitTermination(90, TimeUnit.SECONDS); if (!result) { System.out.println( "Not all Loggly messages sent out - still had " + pool.getQueue().size() + " left :("); pool.shutdownNow(); } } catch (InterruptedException e) { // ignore } } finally { httpClient.getConnectionManager().shutdown(); System.out.println("Loggly handler shut down"); } }
/** Shuts down internal thread pools. */ public void shutdown() { refreshExecutor.shutdownNow(); refreshTimer.cancel(); }
public void stop() { threadPoolExecutor.shutdownNow(); }
public void shutdown() { executorService_.shutdownNow(); }