@Override public void execute(Runnable command) { if (command == null) { throw new NullPointerException(); } // do not increment in method beforeExecute! submittedTaskCount.incrementAndGet(); try { super.execute(command); } catch (RejectedExecutionException rx) { // retry to offer the task into queue. final TaskQueue queue = (TaskQueue) super.getQueue(); try { if (!queue.retryOffer(command, 0, TimeUnit.MILLISECONDS)) { submittedTaskCount.decrementAndGet(); throw new RejectedExecutionException("Queue capacity is full.", rx); } } catch (InterruptedException x) { submittedTaskCount.decrementAndGet(); throw new RejectedExecutionException(x); } } catch (Throwable t) { // decrease any way submittedTaskCount.decrementAndGet(); throw t; } } }
public static void logRejectionWarning(RejectedExecutionException e) { logger.warn("The limit of pending tasks for the executor is reached. " + "This could be due to a unreachable service such as elasticsearch or due to a spike in incoming requests. " + "Consider increasing the default capacity limit with the configuration key '" + CorePlugin.POOLS_QUEUE_CAPACITY_LIMIT_KEY + "'\n" + e.getMessage()); }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { if (executor.isShutdown()) { throw new RejectedExecutionException("executor has been shutdown"); } else { try { executor.getQueue().put(r); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); RejectedExecutionException e = new RejectedExecutionException("interrupted"); e.initCause(ie); throw e; } } } }
@Override public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit) { if (task == null) { throw new NullPointerException("task"); } if (unit == null) { throw new NullPointerException("unit"); } long pendingTimeoutsCount = pendingTimeouts.incrementAndGet(); if (maxPendingTimeouts > 0 && pendingTimeoutsCount > maxPendingTimeouts) { pendingTimeouts.decrementAndGet(); throw new RejectedExecutionException("Number of pending timeouts (" + pendingTimeoutsCount + ") is greater than or equal to maximum allowed pending " + "timeouts (" + maxPendingTimeouts + ")"); } start(); // Add the timeout to the timeout queue which will be processed on the next tick. // During processing all the queued HashedWheelTimeouts will be added to the correct HashedWheelBucket. long deadline = System.nanoTime() + unit.toNanos(delay) - startTime; // Guard against overflow. if (delay > 0 && deadline < 0) { deadline = Long.MAX_VALUE; } HashedWheelTimeout timeout = new HashedWheelTimeout(this, task, deadline); timeouts.add(timeout); return timeout; }
@Override public void execute(Runnable command) { if (!tasks.offer(command)) { throw new RejectedExecutionException(); } if (state.compareAndSet(NONE, SUBMITTED)) { // Actually it could happen that the runnable was picked up in between but we not care to much and just // execute ourself. At worst this will be a NOOP when run() is called. try { executor.execute(this); } catch (Throwable e) { // Not reset the state as some other Runnable may be added to the queue already in the meantime. tasks.remove(command); PlatformDependent.throwException(e); } } } }
protected final void registerTask(Runnable task) { taskQueue.add(task); Selector selector = this.selector; if (selector != null) { if (wakenUp.compareAndSet(false, true)) { selector.wakeup(); } } else { if (taskQueue.remove(task)) { // the selector was null this means the Worker has already been shutdown. throw new RejectedExecutionException("Worker has already been shutdown"); } } }
public void execute(Runnable task) { try { super.execute(task); } catch (RejectedExecutionException e) { throw new RejectedExecutionException(LocalizationMessages.TRANSPORT_EXECUTOR_CLOSED(), e); if (!taskQueue.offer(task)) { throw new RejectedExecutionException(LocalizationMessages.TRANSPORT_EXECUTOR_QUEUE_LIMIT_REACHED(), e); if (!taskQueue.offer(task)) { throw new RejectedExecutionException(LocalizationMessages.TRANSPORT_EXECUTOR_QUEUE_LIMIT_REACHED(), e); dequeuedTask = taskQueue.poll(); } else { synchronized (taskQueue) {
private EventLoop nextChild() throws Exception { if (shuttingDown) { throw new RejectedExecutionException("shutting down"); } EventLoop loop = idleChildren.poll(); if (loop == null) { if (maxChannels > 0 && activeChildren.size() >= maxChannels) { throw tooManyChannels; } loop = newChild(childArgs); loop.terminationFuture().addListener(childTerminationListener); } activeChildren.add(loop); return loop; } }
@Override public Disposable schedule(Runnable task, long delay, TimeUnit unit) { if (tasksRemaining.decrementAndGet() < 0) throw new RejectedExecutionException("BoundedScheduler schedule with delay: no more tasks"); return actual.schedule(task, delay, unit); }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { if (LOGGER.isWarnEnabled()) { LOGGER.warn(LogCodes.getLog(LogCodes.ERROR_PROVIDER_TR_POOL_REJECTION, executor.getActiveCount(), executor.getPoolSize(), executor.getLargestPoolSize(), executor .getCorePoolSize(), executor.getMaximumPoolSize(), executor.getQueue() .size(), executor.getQueue().remainingCapacity())); } throw new RejectedExecutionException(); } }
public LinkedBlockingQueueSubscribableChannel(BlockingQueue<Runnable> theQueue, String theThreadNamingPattern) { ThreadFactory threadFactory = new BasicThreadFactory.Builder() .namingPattern(theThreadNamingPattern) .daemon(false) .priority(Thread.NORM_PRIORITY) .build(); RejectedExecutionHandler rejectedExecutionHandler = (theRunnable, theExecutor) -> { ourLog.info("Note: Executor queue is full ({} elements), waiting for a slot to become available!", theQueue.size()); StopWatch sw = new StopWatch(); try { theQueue.put(theRunnable); } catch (InterruptedException theE) { throw new RejectedExecutionException("Task " + theRunnable.toString() + " rejected from " + theE.toString()); } ourLog.info("Slot become available after {}ms", sw.getMillis()); }; ThreadPoolExecutor executor = new ThreadPoolExecutor( 1, SubscriptionConstants.EXECUTOR_THREAD_COUNT, 0L, TimeUnit.MILLISECONDS, theQueue, threadFactory, rejectedExecutionHandler); myQueue = theQueue; mySubscribableChannel = new ExecutorSubscribableChannel(executor); }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor e) { String msg = String.format("Thread pool is EXHAUSTED!" + " Thread Name: %s, Pool Size: %d (active: %d, core: %d, max: %d, largest: %d), Task: %d (completed: %d)," + " Executor status:(isShutdown:%s, isTerminated:%s, isTerminating:%s), in %s://%s:%d!", threadName, e.getPoolSize(), e.getActiveCount(), e.getCorePoolSize(), e.getMaximumPoolSize(), e.getLargestPoolSize(), e.getTaskCount(), e.getCompletedTaskCount(), e.isShutdown(), e.isTerminated(), e.isTerminating(), url.getProtocol(), url.getIp(), url.getPort()); logger.warn(msg); dumpJStack(); throw new RejectedExecutionException(msg); }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { try { executor.getQueue().put(r); } catch (InterruptedException e) { throw new RejectedExecutionException("Got Interrupted while adding to the Queue", e); } } }
public static ExecutorService newThreadPoolWithSynchronousFeedThatHandlesRejection( String threadName, ThreadInitializer threadInitializer, CommandWrapper commandWrapper, int corePoolSize, int maximumPoolSize, long keepAliveSeconds) { final BlockingQueue<Runnable> blockingQueue = new SynchronousQueue<>(); final RejectedExecutionHandler rejectedExecutionHandler = (r, pool) -> { try { blockingQueue.put(r); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); // preserve the state throw new RejectedExecutionException("interrupted", ex); } }; ThreadFactory threadFactory = new LoggingThreadFactory(threadName, threadInitializer, commandWrapper); return new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveSeconds, SECONDS, blockingQueue, threadFactory, rejectedExecutionHandler); }
@Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { if (i++ % 7 == 0) { i = 1; if (LOGGER.isWarnEnabled()) { LOGGER.warn("Task:{} has been reject because of threadPool exhausted!" + " pool:{}, active:{}, queue:{}, taskcnt: {}", r, executor.getPoolSize(), executor.getActiveCount(), executor.getQueue().size(), executor.getTaskCount()); } } throw new RejectedExecutionException("Callback handler thread pool has bean exhausted"); } };
private void countAndThrow() { int v = countdown.getAndIncrement(); if (v % 2 == 1) { throw new RejectedExecutionException(); } }
@Override public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { ((DebuggableThreadPoolExecutor) executor).onInitialRejection(task); BlockingQueue<Runnable> queue = executor.getQueue(); while (true) { if (executor.isShutdown()) { ((DebuggableThreadPoolExecutor) executor).onFinalRejection(task); throw new RejectedExecutionException("ThreadPoolExecutor has shut down"); } try { if (queue.offer(task, 1000, TimeUnit.MILLISECONDS)) { ((DebuggableThreadPoolExecutor) executor).onFinalAccept(task); break; } } catch (InterruptedException e) { throw new AssertionError(e); } } } };
return; b.readPosition(0); result.add(b); throw new RejectedExecutionException(); }, 1, 1, TimeUnit.MICROSECONDS); final Bytes bytes = result.poll(10, TimeUnit.SECONDS); try { if (bytes == null) {
@Override public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) { try { executor.getQueue().offer(r, 60, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new RejectedExecutionException("Interrupted waiting for BrokerService.worker"); } throw new RejectedExecutionException("Timed Out while attempting to enqueue Task."); } });
public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { while (true) { if (executor.isShutdown()) throw new RejectedExecutionException("ThreadPoolExecutor has shut down"); try { if (queue.offer(task, 1000, TimeUnit.MILLISECONDS)) break; } catch (InterruptedException e) { // NOP } } } }