Code example for ScheduledThreadPoolExecutor

Methods: invokeAllgetQueue

0
    } 
 
    @Override 
    public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException {
        if (canScheduleOrExecute()) { 
            return delegate.invokeAll(tasks, timeout, timeUnit);
        } else { 
            throw new RejectedExecutionException("Task rejected due queue size limit reached");
        } 
    } 
 
    @Override 
    public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
        if (canScheduleOrExecute()) { 
            return delegate.invokeAny(tasks);
        } else { 
            throw new RejectedExecutionException("Task rejected due queue size limit reached");
        } 
    } 
 
    @Override 
    public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
        if (canScheduleOrExecute()) { 
            return delegate.invokeAny(tasks, timeout, timeUnit);
        } else { 
            throw new RejectedExecutionException("Task rejected due queue size limit reached");
        } 
    } 
 
    @Override 
    public boolean isShutdown() { 
        return delegate.isShutdown();
    } 
 
    @Override 
    public boolean isTerminated() { 
        return delegate.isTerminated();
    } 
 
    public boolean isTerminating() { 
        return delegate.isTerminating();
    } 
 
    public int prestartAllCoreThreads() { 
        return delegate.prestartAllCoreThreads();
    } 
 
    public boolean prestartCoreThread() { 
        return delegate.prestartCoreThread();
    } 
 
    public void purge() { 
        delegate.purge();
    } 
 
    public void setCorePoolSize(int corePoolSize) {
        delegate.setCorePoolSize(corePoolSize);
    } 
 
    public void setKeepAliveTime(long keepAliveTime, TimeUnit timeUnit) {
        delegate.setKeepAliveTime(keepAliveTime, timeUnit);
    } 
 
    public void setMaximumPoolSize(int maximumPoolSize) {
        delegate.setMaximumPoolSize(maximumPoolSize);
    } 
 
    public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) {
        delegate.setRejectedExecutionHandler(rejectedExecutionHandler);
    } 
 
    public void setThreadFactory(ThreadFactory threadFactory) {
        delegate.setThreadFactory(threadFactory);
    } 
 
    @Override 
    public void shutdown() { 
        delegate.shutdown();
    } 
 
    @Override 
    public List<Runnable> shutdownNow() {
        return delegate.shutdownNow();
    } 
 
    @Override 
    public <T> Future<T> submit(Callable<T> task) {
        if (canScheduleOrExecute()) { 
            return delegate.submit(task);
        } else { 
            throw new RejectedExecutionException("Task rejected due queue size limit reached");
        } 
    } 
 
    @Override 
    public Future<?> submit(Runnable task) {
        if (canScheduleOrExecute()) { 
            return delegate.submit(task);
        } else { 
            throw new RejectedExecutionException("Task rejected due queue size limit reached");
        } 
    } 
 
    @Override 
    public <T> Future<T> submit(Runnable task, T result) {
        if (canScheduleOrExecute()) { 
            return delegate.submit(task, result);
        } else { 
            throw new RejectedExecutionException("Task rejected due queue size limit reached");
        } 
    } 
 
    @Override 
    public void execute(Runnable task) {
        if (canScheduleOrExecute()) { 
            delegate.execute(task);
        } else { 
            throw new RejectedExecutionException("Task rejected due queue size limit reached");
        } 
    } 
 
    public void allowCoreThreadTimeOut(boolean value) {
        delegate.allowCoreThreadTimeOut(value);
    } 
 
    public boolean allowsCoreThreadTimeOut() { 
        return delegate.allowsCoreThreadTimeOut();
    } 
 
    /** 
     * Can the task be scheduled or executed? 
     * 
     * @return <tt>true</tt> to accept, <tt>false</tt> to not accept 
     */ 
    protected boolean canScheduleOrExecute() { 
        if (queueSize <= 0) {
            return true; 
        } 
 
        int size = delegate.getQueue().size();
        boolean answer = size < queueSize;
        if (LOG.isTraceEnabled()) { 
            LOG.trace("canScheduleOrExecute {} < {} -> {}", new Object[]{size, queueSize, answer}); 
        } 
        return answer;