publicbooleanforce(Runnable o) { if ( parent==null || parent.isShutdown() ) thrownewRejectedExecutionException("Executor not running, can't force a command into the queue"); returnsuper.offer(o); //forces the item onto the queue, to be used if the task is rejected }
publicbooleanforce(Runnable o, long timeout, TimeUnit unit)throws InterruptedException { if ( parent==null || parent.isShutdown() ) thrownewRejectedExecutionException("Executor not running, can't force a command into the queue"); returnsuper.offer(o,timeout,unit); //forces the item onto the queue, to be used if the task is rejected }
@Override publicbooleanoffer(Runnable o) { //we can't do any checks if (parent==null) returnsuper.offer(o); //we are maxed out on threads, simply queue the object if (parent.getPoolSize() == parent.getMaximumPoolSize()) returnsuper.offer(o); //we have idle threads, just add it to the queue if (parent.getSubmittedCount()<(parent.getPoolSize())) returnsuper.offer(o); //if we have less threads than maximum force creation of a new thread if (parent.getPoolSize()<parent.getMaximumPoolSize()) returnfalse; //if we reached here, we need to add it to the queue returnsuper.offer(o); }