/** * Creates a runtime {@link RejectedExecutionException} for {@link ExecutionRejectedException}. * This version takes the {@link ExecutionRejectedException#isFatal()} value into account * and creates {@link FatalRejectedExecutionException} if required. * @param message Message * @param cause Base non-Runtime exception * @return Created Runtime exception */ @Nonnull public static RejectedExecutionException createRuntimeException( @Nonnull String message, @Nonnull ExecutionRejectedException cause) { if (cause.isFatal()) { return new FatalRejectedExecutionException(message, cause); } else { return new RejectedExecutionException(message, cause); } }
@Override public synchronized void execute(Runnable command) { if (shuttingDown) { throw new FatalRejectedExecutionException("Cannot execute the command " + command + ". The executor service is shutting down"); } this.tasks.add(command); // If we haven't been scheduled yet, do so now if (!scheduled) { scheduled = true; try { // Submit task in the async mode ExecutorServiceUtils.submitAsync(base, runner); } catch (ExecutorServiceUtils.ExecutionRejectedException ex) { // Wrap by the runtime exception since there is no other solution here throw new RejectedExecutionException("Base executor service " + base + " has rejected the task " + command, ex); } } }
public void execute(Runnable command) { synchronized (q) { if (isShutdown()) { // No way this executor service can be recovered throw new FatalRejectedExecutionException("This executor has been shutdown."); } q.add(command); if (!isAlive()) { worker = factory.newThread(new Worker()); worker.start(); } } }