List of usage examples for java.util.concurrent ExecutorService isShutdown
boolean isShutdown();
From source file:com.baifendian.swordfish.execserver.runner.flow.FlowRunnerManager.java
/** * executor service//from w ww .j ava2 s . c o m */ private void shutdownExecutorService(ExecutorService executorService, boolean shutdownNow) { if (!executorService.isShutdown()) { try { if (!shutdownNow) { executorService.shutdown(); } else { executorService.shutdownNow(); } executorService.awaitTermination(3, TimeUnit.SECONDS); } catch (Exception e) { logger.error(e.getMessage(), e); } } }
From source file:com.nts.alphamale.handler.ExecutorHandler.java
public void shutdownExecutor(ExecutorService executor, int awaitTermination) { if (null != executor && !executor.isShutdown()) { executor.shutdown();/*from w ww . j a v a2s . com*/ try { if (!executor.awaitTermination(awaitTermination, TimeUnit.SECONDS)) { executor.shutdownNow(); if (!executor.awaitTermination(awaitTermination, TimeUnit.SECONDS)) { log.error("Executor did not terminate"); } } } catch (InterruptedException e) { executor.shutdownNow(); } } }
From source file:com.adaptris.core.lifecycle.FilteredSharedComponentStart.java
private ExecutorService getExecutor(String name) { ExecutorService es = connectionStarters.get(name); if (es == null || es.isShutdown()) { es = Executors.newSingleThreadExecutor(new ManagedThreadFactory(getClass().getSimpleName())); connectionStarters.put(name, es); }/*w w w. j a va 2 s. c o m*/ return es; }
From source file:org.apache.axis2.jaxws.core.controller.impl.InvocationControllerImpl.java
public Future<?> invokeAsync(InvocationContext ic, AsyncHandler asyncHandler) { if (log.isDebugEnabled()) { log.debug("Invocation pattern: asynchronous(callback)"); }//from w w w. ja va 2s . c o m // Check to make sure we at least have a valid InvocationContext // and request MessageContext if (ic == null) { throw ExceptionFactory.makeWebServiceException(Messages.getMessage("ICErr1")); } if (ic.getRequestMessageContext() == null) { throw ExceptionFactory.makeWebServiceException(Messages.getMessage("ICErr2")); } if ((ic.getExecutor() != null) && (ic.getExecutor() instanceof ExecutorService)) { ExecutorService es = (ExecutorService) ic.getExecutor(); if (es.isShutdown()) { // the executor service is shutdown and won't accept new tasks // so return an error back to the client throw ExceptionFactory.makeWebServiceException(Messages.getMessage("ExecutorShutdown")); } } MessageContext request = ic.getRequestMessageContext(); request.setProperty(Constants.INVOCATION_PATTERN, InvocationPattern.ASYNC_CALLBACK); Future<?> future = null; // Invoke outbound handlers. boolean success = HandlerInvokerUtils.invokeOutboundHandlers(request.getMEPContext(), ic.getHandlers(), HandlerChainProcessor.MEP.REQUEST, false); if (success) { // If there are any headers understood by handlers, then set a property // on the message context so the response mustUnderstand processing takes those // understood headers into consideration. registerUnderstoodHeaders(request, ic.getHandlers()); prepareRequest(request); future = doInvokeAsync(request, asyncHandler); } else { // the outbound handler chain must have had a problem, and // we've reversed directions // since we've reversed directions, the message has "become a // response message" (section 9.3.2.1, footnote superscript 2) // TODO: how do we deal with this? The response message may or may // not be a fault // message. We do know that the direction has reversed, so somehow // we need to // flow immediately out of the async and give the exception and/or // response object // back to the client app without calling // AsyncResponse.processResponse or processFault throw ExceptionFactory.makeWebServiceException(Messages.getMessage("invokeAsyncErr")); // throw new AxisFault(request.getMessage()); } return future; }
From source file:com.amazonaws.services.cloudtrail.processinglibrary.AWSCloudTrailProcessingExecutor.java
/** * Helper function to gracefully stop an {@link ExecutorService}. * * @param threadPool the thread pool to stop. *//*from w w w .j ava 2s. c o m*/ private void stopThreadPool(ExecutorService threadPool) { LibraryUtils.checkCondition(threadPool == null, "Thread pool is null when calling stop"); if (threadPool.isShutdown()) { logger.debug(threadPool.toString() + " is already stopped."); } else { logger.debug(threadPool.toString() + " is about to shutdown."); threadPool.shutdown(); // Shutdown thread pool try { // Wait for shutdown threadPool.awaitTermination(this.config.getThreadTerminationDelaySeconds(), TimeUnit.SECONDS); } catch (InterruptedException e) { logger.debug("Wait thread pool termination is interrupted."); } if (!threadPool.isShutdown()) { // ShutdownNow after waiting logger.debug(threadPool.toString() + " is force to shutdown now."); threadPool.shutdownNow(); } logger.debug(threadPool.toString() + " is stopped."); } }
From source file:org.apache.camel.impl.DefaultExecutorServiceStrategy.java
public void shutdown(ExecutorService executorService) { ObjectHelper.notNull(executorService, "executorService"); if (executorService.isShutdown()) { return;/* w ww . ja v a 2 s . c om*/ } if (LOG.isDebugEnabled()) { LOG.debug("Shutdown ExecutorService: " + executorService); } executorService.shutdown(); if (LOG.isTraceEnabled()) { LOG.trace("Shutdown ExecutorService: " + executorService + " complete."); } }
From source file:org.apache.camel.impl.DefaultExecutorServiceStrategy.java
public List<Runnable> shutdownNow(ExecutorService executorService) { ObjectHelper.notNull(executorService, "executorService"); if (executorService.isShutdown()) { return null; }/*w ww. j a v a 2 s .c om*/ if (LOG.isDebugEnabled()) { LOG.debug("ShutdownNow ExecutorService: " + executorService); } List<Runnable> answer = executorService.shutdownNow(); if (LOG.isTraceEnabled()) { LOG.trace("ShutdownNow ExecutorService: " + executorService + " complete."); } return answer; }
From source file:com.esri.cordova.geolocation.AdvancedGeolocation.java
/** * Shutdown cordova thread pool. This assumes we are in control of all tasks running * in the thread pool.// www . j a v a 2s .c o m * Additional info: http://developer.android.com/reference/java/util/concurrent/ExecutorService.html * @param pool Cordova application's thread pool */ private void shutdownAndAwaitTermination(ExecutorService pool) { Log.d(TAG, "Attempting to shutdown cordova threadpool"); if (!pool.isShutdown()) { try { // Disable new tasks from being submitted pool.shutdown(); // Wait a while for existing tasks to terminate if (!pool.awaitTermination(5, TimeUnit.SECONDS)) { pool.shutdownNow(); // Cancel currently executing tasks // Wait a while for tasks to respond to being cancelled if (!pool.awaitTermination(30, TimeUnit.SECONDS)) { System.err.println("Cordova thread pool did not terminate."); } } } catch (InterruptedException ie) { // Preserve interrupt status Thread.currentThread().interrupt(); } } }
From source file:com.brienwheeler.lib.concurrent.ExecutorsTest.java
@Test public void testNewSingleThreadExecutorShutdownNow() throws InterruptedException { NamedThreadFactory threadFactory = new NamedThreadFactory(THREAD_FACTORY_NAME); ExecutorService executor = Executors.newSingleThreadExecutor(threadFactory); executor.submit(new SleepRunnable(10L)); Future<?> notExecutedRunnable = executor.submit(new NullRunnable()); Future<?> notExecutedCallable = executor.submit(new NullCallable()); Future<Integer> notEexecutedRunnable2 = executor.submit(new NullRunnable(), 1); List<Runnable> notExecuted = executor.shutdownNow(); Assert.assertTrue(executor.isShutdown()); Assert.assertEquals(3, notExecuted.size()); Assert.assertTrue(CollectionUtils.containsInstance(notExecuted, notExecutedRunnable)); Assert.assertTrue(CollectionUtils.containsInstance(notExecuted, notExecutedCallable)); Assert.assertTrue(CollectionUtils.containsInstance(notExecuted, notEexecutedRunnable2)); executor.awaitTermination(10, TimeUnit.MILLISECONDS); Assert.assertTrue(executor.isTerminated()); }
From source file:org.csc.phynixx.connection.MTPooledConnectionIT.java
private void startRunners(IActOnConnection actOnConnection, int numThreads) throws Exception { exceptions.clear();//from w w w . j a va 2 s . c o m ExecutorService executorService = Executors.newFixedThreadPool(numThreads); for (int i = 0; i < numThreads; i++) { Callable<Object> task = new Caller(actOnConnection); executorService.submit(task); } executorService.shutdown(); // 10 seconds per execution boolean inTime = executorService.awaitTermination(10000 * CONNECTION_POOL_SIZE, TimeUnit.SECONDS); if (!inTime) { if (!executorService.isShutdown()) { List<Runnable> runnables = executorService.shutdownNow(); } throw new IllegalStateException( "Execution was stopped after " + 10 * CONNECTION_POOL_SIZE + " seconds"); } if (exceptions.size() > 0) { for (int i = 0; i < exceptions.size(); i++) { Exception ex = (Exception) exceptions.get(i); ex.printStackTrace(); } throw new IllegalStateException("Error occurred", exceptions.get(0)); } }