776 |
|
|
777 |
|
|
778 |
|
/** |
779 |
+ |
* Removes from the work queue all {@ link Cancellable} tasks |
780 |
+ |
* that have been cancelled. This method can be useful as a |
781 |
+ |
* storage reclamation operation, that has no other impact |
782 |
+ |
* on functionality. Cancelled tasks are never executed, but |
783 |
+ |
* may accumulate in work queues until worker threads can |
784 |
+ |
* actively remove them. Invoking this method ensures that they |
785 |
+ |
* are instead removed now. |
786 |
+ |
*/ |
787 |
+ |
|
788 |
+ |
public void purge() { |
789 |
+ |
Iterator<Runnable> it = getQueue().iterator(); |
790 |
+ |
while (it.hasNext()) { |
791 |
+ |
Runnable r = it.next(); |
792 |
+ |
if (r instanceof Cancellable) { |
793 |
+ |
Cancellable c = (Cancellable)r; |
794 |
+ |
if (c.isCancelled()) |
795 |
+ |
it.remove(); |
796 |
+ |
} |
797 |
+ |
} |
798 |
+ |
} |
799 |
+ |
|
800 |
+ |
/** |
801 |
|
* Sets the core number of threads. This overrides any value set |
802 |
|
* in the constructor. If the new value is smaller than the |
803 |
|
* current value, excess existing threads will be terminated when |