/** * 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"); }
/** * Stops the reactor and related resources such as dispatcher. * * @throws InterruptedException * if interrupted while stopping the reactor. * @throws IOException * if any I/O error occurs. */ public void stop() throws InterruptedException, IOException { reactorMain.shutdownNow(); selector.wakeup(); reactorMain.awaitTermination(4, TimeUnit.SECONDS); selector.close(); LOGGER.info("Reactor stopped"); }
public void shutdown() { this.executorService.shutdown(); this.executorService.shutdownNow(); } }
private void setConfigParallel(FileSystem outputFs, List<Path> traversedPath, BiConsumer<FileSystem, Path> task, Configuration conf) throws IOException { ExecutorService pool = Executors .newFixedThreadPool(conf.getInt(CONF_COPY_MANIFEST_THREADS, DEFAULT_COPY_MANIFEST_THREADS)); List<Future<Void>> futures = new ArrayList<>(); for (Path dstPath : traversedPath) { Future<Void> future = (Future<Void>) pool.submit(() -> task.accept(outputFs, dstPath)); futures.add(future); } try { for (Future<Void> future : futures) { future.get(); } } catch (InterruptedException | ExecutionException e) { throw new IOException(e); } finally { pool.shutdownNow(); } }
@Override public void run() { ExecutorService executor = Executors.newSingleThreadExecutor(); try { Future future = executor.submit(monitored::stop); future.get(terminationTimeoutMs, TimeUnit.MILLISECONDS); } catch (Exception e) { LoggerFactory.getLogger(getClass()).error("Can not stop in {}ms", terminationTimeoutMs, e); } executor.shutdownNow(); commands.endWatch(); } }
public void run() { ExecutorService service = Executors.newSingleThreadExecutor(); Callable<Object> callable = new Callable<Object>() { public Object call() throws Exception { runTestMethod(); return null; } }; Future<Object> result = service.submit(callable); service.shutdown(); try { boolean terminated = service.awaitTermination(timeout, TimeUnit.MILLISECONDS); if (!terminated) { service.shutdownNow(); } result.get(0, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation } catch (TimeoutException e) { addFailure(new Exception(String.format("test timed out after %d milliseconds", timeout))); } catch (Exception e) { addFailure(e); } } });
@Test public void testGetInputSummaryPoolAndFailure() throws ExecutionException, InterruptedException, IOException { ExecutorService pool = mock(ExecutorService.class); when(pool.submit(any(Runnable.class))).thenReturn(mock(Future.class)); Set<Path> pathNeedProcess = new HashSet<>(); pathNeedProcess.add(new Path("dummy-path1")); pathNeedProcess.add(new Path("dummy-path2")); pathNeedProcess.add(new Path("dummy-path3")); SessionState.start(new HiveConf()); JobConf jobConf = new JobConf(); Context context = new Context(jobConf); Utilities.getInputSummaryWithPool(context, pathNeedProcess, mock(MapWork.class), new long[3], pool); verify(pool, times(3)).submit(any(Runnable.class)); verify(pool).shutdown(); verify(pool).shutdownNow(); }
ExecutorService executor = newSingleThreadExecutor(); Future<V> waiter = executor.submit( new Callable<V>() { @Override throw failureWithCause(e, "Unexpected exception"); } finally { executor.shutdownNow();
public static List<Path> copyFilesParallel(FileSystem srcFS, Path src, FileSystem dstFS, Path dst, Configuration conf, int threads) throws IOException { ExecutorService pool = Executors.newFixedThreadPool(threads); List<Future<Void>> futures = new ArrayList<>(); List<Path> traversedPaths; try { traversedPaths = copyFiles(srcFS, src, dstFS, dst, conf, pool, futures); for (Future<Void> future : futures) { future.get(); } } catch (ExecutionException | InterruptedException | IOException e) { throw new IOException("copy snapshot reference files failed", e); } finally { pool.shutdownNow(); } return traversedPaths; }
@Test public void required_spec312_cancelMustMakeThePublisherToEventuallyStopSignaling_shouldFailBy_havingEmitedMoreThanRequested() throws Throwable { final ExecutorService pool = Executors.newFixedThreadPool(2); try { requireTestFailure(new ThrowingRunnable() { @Override public void run() throws Throwable { demandIgnoringAsynchronousPublisherVerification(pool).required_spec312_cancelMustMakeThePublisherToEventuallyStopSignaling(); } }, /*Publisher signalled [...] */ ", which is more than the signalled demand: "); } finally { pool.shutdownNow(); pool.awaitTermination(1, TimeUnit.SECONDS); } }
public void reset() { pool.shutdownNow(); pool=Executors.newFixedThreadPool(numThread); f= new ArrayList<Future>(); }
@Test public void multiThreadedProducer() { UnicastProcessor<Integer> processor = UnicastProcessor.create(); FluxSink<Integer> sink = processor.sink(); int nThreads = 5; int countPerThread = 10000; ExecutorService executor = Executors.newFixedThreadPool(nThreads); for (int i = 0; i < 5; i++) { Runnable generator = () -> { for (int j = 0; j < countPerThread; j++) { sink.next(j); } }; executor.submit(generator); } StepVerifier.create(processor) .expectNextCount(nThreads * countPerThread) .thenCancel() .verify(); executor.shutdownNow(); }
public static void main(String args[]) throws InterruptedException { ExecutorService executor = Executors.newFixedThreadPool(1); executor.submit(new Runnable() { @Override public void run() { while (true) { if (Thread.currentThread().isInterrupted()) break; } } }); executor.shutdownNow(); if (!executor.awaitTermination(100, TimeUnit.MICROSECONDS)) { System.out.println("Still waiting..."); System.exit(0); } System.out.println("Exiting normally..."); }
private void shutdownAndAwaitTermination(ExecutorService pool) { pool.shutdown(); try { if (!pool.awaitTermination(3, TimeUnit.SECONDS)) { pool.shutdownNow(); } } catch (InterruptedException e) { logger.warn("InstanceInfoReplicator stop interrupted"); } }
public static void main(String[] args) throws Exception { ExecutorService executor = Executors.newSingleThreadExecutor(); Future<String> future = executor.submit(new Task()); System.out.println(future.get(3, TimeUnit.SECONDS)); System.out.println("Finished!"); } catch (TimeoutException e) { executor.shutdownNow();
public void run() { ExecutorService service = Executors.newSingleThreadExecutor(); Callable<Object> callable = new Callable<Object>() { public Object call() throws Exception { runTestMethod(); return null; } }; Future<Object> result = service.submit(callable); service.shutdown(); try { boolean terminated = service.awaitTermination(timeout, TimeUnit.MILLISECONDS); if (!terminated) { service.shutdownNow(); } result.get(0, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation } catch (TimeoutException e) { addFailure(new TestTimedOutException(timeout, TimeUnit.MILLISECONDS)); } catch (Exception e) { addFailure(e); } } });
@Test public void testGetInputSummaryPool() throws ExecutionException, InterruptedException, IOException { ExecutorService pool = mock(ExecutorService.class); when(pool.submit(any(Runnable.class))).thenReturn(mock(Future.class)); Set<Path> pathNeedProcess = new HashSet<>(); pathNeedProcess.add(new Path("dummy-path1")); pathNeedProcess.add(new Path("dummy-path2")); pathNeedProcess.add(new Path("dummy-path3")); SessionState.start(new HiveConf()); JobConf jobConf = new JobConf(); Context context = new Context(jobConf); Utilities.getInputSummaryWithPool(context, pathNeedProcess, mock(MapWork.class), new long[3], pool); verify(pool, times(3)).submit(any(Runnable.class)); verify(pool).shutdown(); verify(pool).shutdownNow(); }
queryExecutor.submit(() -> { try { statement.execute("SELECT 1 AS col1 FROM tpch.sf1.lineitem CROSS JOIN tpch.sf1.lineitem"); queryExecutor.shutdownNow();
@Override public void close() throws IOException { this.active = false; this.service.shutdownNow(); try { this.service.awaitTermination(1L, TimeUnit.SECONDS); } catch (InterruptedException e) { LOG.error("Failed to close assignments distribute service"); } this.assignmentsQueue = null; }
@Test public void required_spec317_mustSupportAPendingElementCountUpToLongMaxValue_shouldFail_onAsynchDemandIgnoringPublisher() throws Throwable { // 10 is arbitrary here, we just need a "larger number" to get into concurrent access scenarios, anything more than 2 // should work, but getting up to 10 should be safer and doesn't hurt to play safe here final ExecutorService pool = Executors.newFixedThreadPool(10); try { requireTestFailure(new ThrowingRunnable() { @Override public void run() throws Throwable { demandIgnoringAsynchronousPublisherVerification(pool).required_spec317_mustSupportAPendingElementCountUpToLongMaxValue(); } }, "Expected end-of-stream but got"); } finally { pool.shutdownNow(); pool.awaitTermination(1, TimeUnit.SECONDS); } }