在阅读 Threadpool executor 的文档时,我看到如下:
当大量排队的任务被取消时,两个提供的方法 remove(java.lang.Runnable) 和 purge() 可用于协助存储回收。
我知道,如果取消任何任务,我可以使用这些方法来清理工作队列。我试图了解实际源中的哪个部分会自动进行清理。假设我从 10 个队列开始,其中 4 个任务被取消,当新任务到达时,队列大小是 6,还是会忽略 4 个取消的任务并重置为 10。
从来源我看到这个评论:
/**
* Tries to remove from the work queue all
* tasks that have been cancelled. This method can be useful as a
* storage reclamation operation, that has no other impact on
* functionality. Cancelled tasks are never executed, but may
* accumulate in work queues until worker threads can actively
* remove them. Invoking this method instead tries to remove them now.
* However, this method may fail to remove tasks in
* the presence of interference by other threads.*
*/
public void purge() {
但是有人可以告诉我工作线程在哪里主动删除源中取消的任务吗?
感谢您的时间,