List of usage examples for java.util.concurrent ExecutorService shutdownNow
List<Runnable> shutdownNow();
From source file:com.addthis.hydra.task.source.DataSourceStreamList.java
void shutdownAndAwaitTermination(ExecutorService... pools) { for (ExecutorService pool : pools) { pool.shutdownNow(); // Disable new tasks from being submitted try {/* ww w. jav a2 s . com*/ // Wait a while for existing tasks to terminate if (!pool.awaitTermination(60, TimeUnit.SECONDS)) { pool.shutdownNow(); // Cancel currently executing tasks // Wait a while for tasks to respond to being cancelled if (!pool.awaitTermination(60, TimeUnit.SECONDS)) { System.err.println("Pool did not terminate"); } } } catch (InterruptedException ie) { // (Re-)Cancel if current thread also interrupted pool.shutdownNow(); // Preserve interrupt status Thread.currentThread().interrupt(); } } }
From source file:org.rhq.metrics.simulator.Simulator.java
private void shutdown(ExecutorService service, String serviceName, int wait) { log.info("Shutting down " + serviceName); service.shutdown();//from w ww . ja va 2 s. c o m try { service.awaitTermination(wait, TimeUnit.SECONDS); } catch (InterruptedException e) { } if (!service.isTerminated()) { log.info("Forcing " + serviceName + " shutdown."); service.shutdownNow(); } log.info(serviceName + " shut down complete"); }
From source file:org.jasig.cas.ticket.registry.support.JpaLockingStrategyTests.java
/** * Test concurrent acquire/release semantics. *///ww w. jav a2s.c o m @Test @IfProfileValue(name = "cas.jpa.concurrent", value = "true") public void testConcurrentAcquireAndRelease() throws Exception { final ExecutorService executor = Executors.newFixedThreadPool(CONCURRENT_SIZE); try { testConcurrency(executor, getConcurrentLocks("concurrent-new")); } catch (Exception e) { logger.debug("testConcurrentAcquireAndRelease produced an error", e); fail("testConcurrentAcquireAndRelease failed."); } finally { executor.shutdownNow(); } }
From source file:org.jasig.cas.ticket.registry.support.JpaLockingStrategyTests.java
/** * Test concurrent acquire/release semantics for existing lock. *///w w w . java 2s . c o m @Test @IfProfileValue(name = "cas.jpa.concurrent", value = "true") public void testConcurrentAcquireAndReleaseOnExistingLock() throws Exception { final LockingStrategy[] locks = getConcurrentLocks("concurrent-exists"); locks[0].acquire(); locks[0].release(); final ExecutorService executor = Executors.newFixedThreadPool(CONCURRENT_SIZE); try { testConcurrency(executor, locks); } catch (Exception e) { logger.debug("testConcurrentAcquireAndReleaseOnExistingLock produced an error", e); fail("testConcurrentAcquireAndReleaseOnExistingLock failed."); } finally { executor.shutdownNow(); } }
From source file:com.tenforce.lodms.extractors.CkanHarvester.java
public void harvest(List<String> datasetIds) throws RDFHandlerException, ExtractException, DatatypeConfigurationException { if (datasetIds.isEmpty()) { throw new ExtractException("no datasets specified"); }/*from w w w . ja v a 2 s . co m*/ if (enableProvenance) addCatalogProvenance(); MapToRdfConverter converter = new MapToRdfConverter(predicatePrefix, ignoredKeys, handler); ExecutorService executorService = Executors.newFixedThreadPool(5); CountDownLatch barrier = new CountDownLatch(datasetIds.size()); Catalog catalog = new Catalog(baseUri, subjectPrefix); try { for (String datasetId : datasetIds) { executorService.execute(new DataSetHarvester(catalog, converter, handler, apiUri, datasetId, barrier, warnings, httpMethod)); } executorService.shutdown(); barrier.await(); } catch (Exception e) { executorService.shutdownNow(); throw new ExtractException(e.getMessage(), e); } }
From source file:org.apache.hadoop.hive.ql.exec.StatsNoJobTask.java
private void shutdownAndAwaitTermination(ExecutorService threadPool) { // Disable new tasks from being submitted threadPool.shutdown();// w ww . j av a 2s. c o m try { // Wait a while for existing tasks to terminate if (!threadPool.awaitTermination(100, TimeUnit.SECONDS)) { // Cancel currently executing tasks threadPool.shutdownNow(); // Wait a while for tasks to respond to being cancelled if (!threadPool.awaitTermination(100, TimeUnit.SECONDS)) { LOG.debug("Stats collection thread pool did not terminate"); } } } catch (InterruptedException ie) { // Cancel again if current thread also interrupted threadPool.shutdownNow(); // Preserve interrupt status Thread.currentThread().interrupt(); } }
From source file:at.wada811.android.library.demos.concurrent.ExecutorActivity.java
/** * ExecutorService ???/*from w w w . j a va 2 s. c o m*/ * * <p> * ?????????????????????1???????<br> * UI?8???????? Handler ???????????? * </p> */ private void shutdown(final ExecutorService executorService) { new Handler().postDelayed(new Runnable() { @Override public void run() { try { LogUtils.d("shutdown"); executorService.shutdown(); if (!executorService.awaitTermination(1, TimeUnit.SECONDS)) { LogUtils.d("shutdownNow"); executorService.shutdownNow(); } } catch (InterruptedException e) { e.printStackTrace(); LogUtils.d("shutdownNow: " + e.getMessage()); executorService.shutdownNow(); } } }, 8000); }
From source file:com.skcraft.launcher.selfupdate.SelfUpdater.java
@Override public File call() throws Exception { ExecutorService executor = Executors.newSingleThreadExecutor(); try {//from ww w . j av a2 s. c o m File dir = launcher.getLauncherBinariesDir(); File file = new File(dir, String.valueOf(System.currentTimeMillis()) + ".jar.pack"); File tempFile = installer.getDownloader().download(url, "", 10000, "launcher.jar.pack"); progress = installer.getDownloader(); installer.download(); installer.queue(new FileMover(tempFile, file)); progress = installer; installer.execute(); updatedAlready = true; return file; } finally { executor.shutdownNow(); } }
From source file:org.apache.syncope.fit.core.AbstractTaskITCase.java
protected void execProvisioningTasks(final TaskService taskService, final Set<String> taskKeys, final int maxWaitSeconds, final boolean dryRun) throws Exception { ExecutorService service = Executors.newFixedThreadPool(taskKeys.size()); List<Future<ExecTO>> futures = new ArrayList<>(); for (String key : taskKeys) { futures.add(service.submit(new ThreadExec(taskService, key, maxWaitSeconds, dryRun))); // avoid flooding the test server try {/*from w ww .j a v a2s .c o m*/ Thread.sleep(2000); } catch (InterruptedException e) { } } for (Future<ExecTO> future : futures) { future.get(100, TimeUnit.SECONDS); } service.shutdownNow(); }
From source file:com.vmware.photon.controller.model.adapters.azure.stats.AzureStatsService.java
private void awaitTermination(ExecutorService executor) { try {/*w w w.j av a 2s .c o m*/ if (!executor.awaitTermination(EXECUTOR_SHUTDOWN_INTERVAL_MINUTES, TimeUnit.MINUTES)) { logWarning("Executor service can't be shutdown for Azure. Trying to shutdown now..."); executor.shutdownNow(); } logFine("Executor service shutdown for Azure"); } catch (InterruptedException e) { logSevere(e); Thread.currentThread().interrupt(); } catch (Exception e) { logSevere(e); } }