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);
}
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));
}
}
}
}
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;
}
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;
}
}
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);
}
Aggregations