Search in sources :

Example 21 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project tomcat by apache.

the class SocketWrapperBase method execute.

/**
     * Transfers processing to a container thread.
     *
     * @param runnable The actions to process on a container thread
     *
     * @throws RejectedExecutionException If the runnable cannot be executed
     */
public void execute(Runnable runnable) {
    Executor executor = endpoint.getExecutor();
    if (!endpoint.isRunning() || executor == null) {
        throw new RejectedExecutionException();
    }
    executor.execute(runnable);
}
Also used : Executor(java.util.concurrent.Executor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 22 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project tomcat by apache.

the class WsRemoteEndpointImplServer method clearHandler.

/**
     *
     * @param t             The throwable associated with any error that
     *                      occurred
     * @param useDispatch   Should {@link SendHandler#onResult(SendResult)} be
     *                      called from a new thread, keeping in mind the
     *                      requirements of
     *                      {@link javax.websocket.RemoteEndpoint.Async}
     */
private void clearHandler(Throwable t, boolean useDispatch) {
    // Setting the result marks this (partial) message as
    // complete which means the next one may be sent which
    // could update the value of the handler. Therefore, keep a
    // local copy before signalling the end of the (partial)
    // message.
    SendHandler sh = handler;
    handler = null;
    buffers = null;
    if (sh != null) {
        if (useDispatch) {
            OnResultRunnable r = new OnResultRunnable(sh, t);
            try {
                socketWrapper.execute(r);
            } catch (RejectedExecutionException ree) {
                // Can't use the executor so call the runnable directly.
                // This may not be strictly specification compliant in all
                // cases but during shutdown only close messages are going
                // to be sent so there should not be the issue of nested
                // calls leading to stack overflow as described in bug
                // 55715. The issues with nested calls was the reason for
                // the separate thread requirement in the specification.
                r.run();
            }
        } else {
            if (t == null) {
                sh.onResult(new SendResult());
            } else {
                sh.onResult(new SendResult(t));
            }
        }
    }
}
Also used : SendHandler(javax.websocket.SendHandler) SendResult(javax.websocket.SendResult) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 23 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project tomcat by apache.

the class AbstractEndpoint method processSocket.

// ---------------------------------------------- Request processing methods
/**
     * Process the given SocketWrapper with the given status. Used to trigger
     * processing as if the Poller (for those endpoints that have one)
     * selected the socket.
     *
     * @param socketWrapper The socket wrapper to process
     * @param event         The socket event to be processed
     * @param dispatch      Should the processing be performed on a new
     *                          container thread
     *
     * @return if processing was triggered successfully
     */
public boolean processSocket(SocketWrapperBase<S> socketWrapper, SocketEvent event, boolean dispatch) {
    try {
        if (socketWrapper == null) {
            return false;
        }
        SocketProcessorBase<S> sc = processorCache.pop();
        if (sc == null) {
            sc = createSocketProcessor(socketWrapper, event);
        } else {
            sc.reset(socketWrapper, event);
        }
        Executor executor = getExecutor();
        if (dispatch && executor != null) {
            executor.execute(sc);
        } else {
            sc.run();
        }
    } catch (RejectedExecutionException ree) {
        getLog().warn(sm.getString("endpoint.executor.fail", socketWrapper), ree);
        return false;
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        // This means we got an OOM or similar creating a thread, or that
        // the pool and its queue are full
        getLog().error(sm.getString("endpoint.process.fail"), t);
        return false;
    }
    return true;
}
Also used : ResizableExecutor(org.apache.tomcat.util.threads.ResizableExecutor) Executor(java.util.concurrent.Executor) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 24 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project cas by apereo.

the class SimpleHttpClient method sendMessageToEndPoint.

@Override
public boolean sendMessageToEndPoint(final HttpMessage message) {
    Assert.notNull(this.httpClient);
    try {
        final HttpPost request = new HttpPost(message.getUrl().toURI());
        request.addHeader("Content-Type", message.getContentType());
        final StringEntity entity = new StringEntity(message.getMessage(), ContentType.create(message.getContentType()));
        request.setEntity(entity);
        final ResponseHandler<Boolean> handler = response -> response.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
        LOGGER.debug("Created HTTP post message payload [{}]", request);
        final HttpRequestFutureTask<Boolean> task = this.requestExecutorService.execute(request, HttpClientContext.create(), handler);
        if (message.isAsynchronous()) {
            return true;
        }
        return task.get();
    } catch (final RejectedExecutionException e) {
        LOGGER.warn(e.getMessage(), e);
        return false;
    } catch (final Exception e) {
        LOGGER.debug(e.getMessage(), e);
        return false;
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpRequestFutureTask(org.apache.http.impl.client.HttpRequestFutureTask) URL(java.net.URL) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) EntityUtils(org.apache.http.util.EntityUtils) FutureRequestExecutionService(org.apache.http.impl.client.FutureRequestExecutionService) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) StringEntity(org.apache.http.entity.StringEntity) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) HttpGet(org.apache.http.client.methods.HttpGet) DisposableBean(org.springframework.beans.factory.DisposableBean) ResponseHandler(org.apache.http.client.ResponseHandler) Collections(java.util.Collections) Assert(org.springframework.util.Assert) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MalformedURLException(java.net.MalformedURLException)

Example 25 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project che by eclipse.

the class CronThreadPoolExecutor method schedule.

@Override
public Future<?> schedule(final Runnable task, final CronExpression expression) {
    if (task == null) {
        throw new NullPointerException();
    }
    setCorePoolSize(getCorePoolSize() + 1);
    Runnable scheduleTask = new Runnable() {

        @Override
        public void run() {
            CountDownLatch countDownLatch = new CountDownLatch(1);
            cronJobWatchDogs.add(countDownLatch);
            Date now = new Date();
            Date time = expression.getNextValidTimeAfter(now);
            try {
                while (time != null) {
                    CronThreadPoolExecutor.this.schedule(task, time.getTime() - now.getTime(), TimeUnit.MILLISECONDS);
                    while (now.before(time)) {
                        LOG.debug("Cron watch dog wait {} ", time.getTime() - now.getTime());
                        if (countDownLatch.await(time.getTime() - now.getTime(), TimeUnit.MILLISECONDS)) {
                            LOG.debug("Stopping cron watch dog.");
                            return;
                        }
                        now = new Date();
                    }
                    time = expression.getNextValidTimeAfter(now);
                }
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            } catch (RejectedExecutionException | CancellationException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    };
    return this.submit(scheduleTask);
}
Also used : CancellationException(java.util.concurrent.CancellationException) CountDownLatch(java.util.concurrent.CountDownLatch) Date(java.util.Date) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)231 ExecutorService (java.util.concurrent.ExecutorService)42 IOException (java.io.IOException)31 Test (org.junit.Test)29 Future (java.util.concurrent.Future)19 ArrayList (java.util.ArrayList)18 ExecutionException (java.util.concurrent.ExecutionException)15 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 Executor (java.util.concurrent.Executor)13 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)12 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