/** *UsedtoaddatasktothequeueifthetaskhasbeenrejectedbytheExecutor. * *@paramoThetasktoaddtothequeue * *@return{@codetrue}ifthetaskwasaddedtothequeue, *otherwise{@codefalse}
*/ publicboolean force(Runnable o) { if (parent == null || parent.isShutdown()) { thrownew RejectedExecutionException(sm.getString("taskQueue.notRunning"));
} returnsuper.offer(o); //forces the item onto the queue, to be used if the task is rejected
}
@Override publicboolean offer(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.getPoolSizeNoLock() == parent.getMaximumPoolSize()) { returnsuper.offer(o);
} //we have idle threads, just add it to the queue if (parent.getSubmittedCount() <= parent.getPoolSizeNoLock()) { returnsuper.offer(o);
} //if we have less threads than maximum force creation of a new thread if (parent.getPoolSizeNoLock() < parent.getMaximumPoolSize()) { returnfalse;
} //if we reached here, we need to add it to the queue returnsuper.offer(o);
}
@Override public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException {
Runnable runnable = super.poll(timeout, unit); if (runnable == null && parent != null) { // the poll timed out, it gives an opportunity to stop the current // thread if needed to avoid memory leaks.
parent.stopCurrentThreadIfNeeded();
} return runnable;
}
@Override public Runnable take() throws InterruptedException { if (parent != null && parent.currentThreadShouldBeStopped()) { return poll(parent.getKeepAliveTime(TimeUnit.MILLISECONDS),
TimeUnit.MILLISECONDS); // yes, this may return null (in case of timeout) which normally // does not occur with take() // but the ThreadPoolExecutor implementation allows this
} returnsuper.take();
}
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.5Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.