use of java.util.concurrent.RejectedExecutionException in project jetty.project by eclipse.
the class TimerScheduler method schedule.
@Override
public Task schedule(final Runnable task, final long delay, final TimeUnit units) {
Timer timer = _timer;
if (timer == null)
throw new RejectedExecutionException("STOPPED: " + this);
SimpleTask t = new SimpleTask(task);
timer.schedule(t, units.toMillis(delay));
return t;
}
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 hive by apache.
the class JobRequestExecutor method execute.
/*
* Executes job request operation. If thread pool is not created then job request is
* executed in current thread itself.
*
* @param jobExecuteCallable
* Callable object to run the job request task.
*
*/
public T execute(JobCallable<T> jobExecuteCallable) throws InterruptedException, TimeoutException, TooManyRequestsException, ExecutionException {
/*
* The callable shouldn't be null to execute. The thread pool also should be configured
* to execute requests.
*/
assert (jobExecuteCallable != null);
assert (this.jobExecutePool != null);
String type = this.requestType.toString().toLowerCase();
String retryMessageForConcurrentRequests = "Please wait for some time before retrying " + "the operation. Please refer to the config " + concurrentRequestsConfigName + " to configure concurrent requests.";
LOG.debug("Starting new " + type + " job request with time out " + this.requestExecutionTimeoutInSec + "seconds.");
Future<T> future = null;
try {
future = this.jobExecutePool.submit(jobExecuteCallable);
} catch (RejectedExecutionException rejectedException) {
/*
* Not able to find thread to execute the job request. Raise Busy exception and client
* can retry the operation.
*/
String tooManyRequestsExceptionMessage = "Unable to service the " + type + " job request as " + "templeton service is busy with too many " + type + " job requests. " + retryMessageForConcurrentRequests;
LOG.warn(tooManyRequestsExceptionMessage);
throw new TooManyRequestsException(tooManyRequestsExceptionMessage);
}
T result = null;
try {
result = this.requestExecutionTimeoutInSec > 0 ? future.get(this.requestExecutionTimeoutInSec, TimeUnit.SECONDS) : future.get();
} catch (TimeoutException e) {
/*
* See if the execution thread has just completed operation and result is available.
* If result is available then return the result. Otherwise, raise exception.
*/
if ((result = tryGetJobResultOrSetJobStateFailed(jobExecuteCallable)) == null) {
String message = this.requestType + " job request got timed out. Please wait for some time " + "before retrying the operation. Please refer to the config " + jobTimeoutConfigName + " to configure job request time out.";
LOG.warn(message);
/*
* Throw TimeoutException to caller.
*/
throw new TimeoutException(message);
}
} catch (InterruptedException e) {
/*
* See if the execution thread has just completed operation and result is available.
* If result is available then return the result. Otherwise, raise exception.
*/
if ((result = tryGetJobResultOrSetJobStateFailed(jobExecuteCallable)) == null) {
String message = this.requestType + " job request got interrupted. Please wait for some time " + "before retrying the operation.";
LOG.warn(message);
/*
* Throw TimeoutException to caller.
*/
throw new InterruptedException(message);
}
} catch (CancellationException e) {
/*
* See if the execution thread has just completed operation and result is available.
* If result is available then return the result. Otherwise, raise exception.
*/
if ((result = tryGetJobResultOrSetJobStateFailed(jobExecuteCallable)) == null) {
String message = this.requestType + " job request got cancelled and thread got interrupted. " + "Please wait for some time before retrying the operation.";
LOG.warn(message);
throw new InterruptedException(message);
}
} finally {
/*
* If the thread is still active and needs to be cancelled then cancel it. This may
* happen in case task got interrupted, or timed out.
*/
if (enableCancelTask) {
cancelExecutePoolThread(future);
}
}
LOG.debug("Completed " + type + " job request.");
return result;
}
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;
}
Aggregations