Search in sources :

Example 76 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project wildfly by wildfly.

the class JobOperatorService method stop.

@Override
public void stop(final StopContext context) {
    // Remove the server activity
    suspendControllerInjector.getValue().unRegisterActivity(serverActivity);
    final ExecutorService service = executorInjector.getValue();
    final Runnable task = () -> {
        // Should already be stopped, but just to be safe we'll make one more attempt
        serverActivity.stopRunningJobs(false);
        batchEnvironment = null;
        classLoader = null;
        context.complete();
    };
    try {
        service.execute(task);
    } catch (RejectedExecutionException e) {
        task.run();
    } finally {
        context.asynchronous();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 77 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project wildfly by wildfly.

the class AbstractResourceAdapterDeploymentService method stopAsync.

protected void stopAsync(final StopContext context, final String deploymentName, final ServiceName serviceName) {
    ExecutorService executorService = getLifecycleExecutorService();
    Runnable r = new Runnable() {

        @Override
        public void run() {
            try {
                DEPLOYMENT_CONNECTOR_LOGGER.debugf("Stopping service %s", serviceName);
                WritableServiceBasedNamingStore.pushOwner(serviceName);
                unregisterAll(deploymentName);
            } finally {
                WritableServiceBasedNamingStore.popOwner();
                context.complete();
            }
        }
    };
    try {
        executorService.execute(r);
    } catch (RejectedExecutionException e) {
        r.run();
    } finally {
        context.asynchronous();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 78 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project wildfly by wildfly.

the class ResourceAdapterDeploymentService method cleanupStartAsync.

// TODO this could be replaced by the superclass method if there is no need for the TCCL change and push/pop owner
// The stop() call doesn't do that so it's probably not needed
private void cleanupStartAsync(final StartContext context, final String deploymentName, final Throwable cause, final ServiceName duServiceName, final ClassLoader toUse) {
    ExecutorService executorService = getLifecycleExecutorService();
    Runnable r = new Runnable() {

        @Override
        public void run() {
            ClassLoader old = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
            try {
                WritableServiceBasedNamingStore.pushOwner(duServiceName);
                WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(toUse);
                unregisterAll(deploymentName);
            } finally {
                try {
                    context.failed(ConnectorLogger.ROOT_LOGGER.failedToStartRaDeployment(cause, deploymentName));
                } finally {
                    WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(old);
                    WritableServiceBasedNamingStore.popOwner();
                }
            }
        }
    };
    try {
        executorService.execute(r);
    } catch (RejectedExecutionException e) {
        r.run();
    } finally {
        context.asynchronous();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 79 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project distributedlog by twitter.

the class TestSafeQueueingFuturePool method testRejectedFailure.

@Test
public void testRejectedFailure() throws Exception {
    TestFuturePool<Void> pool = new TestFuturePool<Void>();
    final AtomicBoolean result = new AtomicBoolean(false);
    pool.executor.shutdown();
    final CountDownLatch latch = new CountDownLatch(1);
    Future<Void> future = pool.wrapper.apply(new Function0<Void>() {

        public Void apply() {
            result.set(true);
            latch.countDown();
            return null;
        }
    });
    try {
        Await.result(future);
        fail("should have thrown");
    } catch (RejectedExecutionException ex) {
    }
    assertFalse(result.get());
    pool.wrapper.close();
    latch.await();
    assertTrue(result.get());
    pool.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 80 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project undertow by undertow-io.

the class Connectors method executeRootHandler.

public static void executeRootHandler(final HttpHandler handler, final HttpServerExchange exchange) {
    try {
        exchange.setInCall(true);
        handler.handleRequest(exchange);
        exchange.setInCall(false);
        boolean resumed = exchange.runResumeReadWrite();
        if (exchange.isDispatched()) {
            if (resumed) {
                UndertowLogger.REQUEST_LOGGER.resumedAndDispatched();
                exchange.setStatusCode(500);
                exchange.endExchange();
                return;
            }
            final Runnable dispatchTask = exchange.getDispatchTask();
            Executor executor = exchange.getDispatchExecutor();
            exchange.setDispatchExecutor(null);
            exchange.unDispatch();
            if (dispatchTask != null) {
                executor = executor == null ? exchange.getConnection().getWorker() : executor;
                try {
                    executor.execute(dispatchTask);
                } catch (RejectedExecutionException e) {
                    UndertowLogger.REQUEST_LOGGER.debug("Failed to dispatch to worker", e);
                    exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
                    exchange.endExchange();
                }
            }
        } else if (!resumed) {
            exchange.endExchange();
        }
    } catch (Throwable t) {
        exchange.putAttachment(DefaultResponseListener.EXCEPTION, t);
        exchange.setInCall(false);
        if (!exchange.isResponseStarted()) {
            exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
        }
        if (t instanceof IOException) {
            UndertowLogger.REQUEST_IO_LOGGER.ioException((IOException) t);
        } else {
            UndertowLogger.REQUEST_LOGGER.undertowRequestFailed(t, exchange);
        }
        exchange.endExchange();
    }
}
Also used : Executor(java.util.concurrent.Executor) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)246 ExecutorService (java.util.concurrent.ExecutorService)42 IOException (java.io.IOException)34 Test (org.junit.Test)34 Future (java.util.concurrent.Future)19 ArrayList (java.util.ArrayList)18 Executor (java.util.concurrent.Executor)18 ExecutionException (java.util.concurrent.ExecutionException)15 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)15 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 List (java.util.List)11 TaskRejectedException (org.springframework.core.task.TaskRejectedException)11 BitmapDrawable (android.graphics.drawable.BitmapDrawable)10 Animation (android.view.animation.Animation)10 Map (java.util.Map)10 CancellationException (java.util.concurrent.CancellationException)10 CacheableBitmapDrawable (uk.co.senab.bitmapcache.CacheableBitmapDrawable)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9