Code example for ThreadPoolExecutor

Methods: getQueue, isShutdown

0
 
    @Override 
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        if (r instanceof AbstractRunnable) {
            if (((AbstractRunnable) r).isForceExecution()) {
                BlockingQueue<Runnable> queue = executor.getQueue();
                if (!(queue instanceof SizeBlockingQueue)) {
                    throw new ElasticSearchIllegalStateException("forced execution, but expected a size queue"); 
                } 
                try { 
                    ((SizeBlockingQueue) queue).forcePut(r);
                } catch (InterruptedException e) {
                    throw new ElasticSearchInterruptedException(e.getMessage(), e);
                } 
                return; 
            } 
        } 
        rejected.inc();
        StringBuilder sb = new StringBuilder("rejected execution ");
        if (executor.isShutdown()) {
            sb.append(SHUTTING_DOWN_KEY + " ");
        } else { 
            if (executor.getQueue() instanceof SizeBlockingQueue) {
                sb.append("(queue capacity ").append(((SizeBlockingQueue) executor.getQueue()).capacity()).append(") ");
            } 
        } 
        sb.append("on ").append(r.toString());
        throw new EsRejectedExecutionException(sb.toString());
    }