[concurrency-interest] Removing jobs from ThreadPoolExecutor

Norman Elton normelton at gmail.com
Fri Sep 2 11:36:50 EDT 2005

I'm using a ThreadPoolExecutor to handle incoming jobs. Jobs are  
either "low priority" or "high priority". I have a separate thread  
that monitors the queue to ensure that it does not get out of control.

I'd like for the monitoring thread to remove all low priority jobs if  
the queue gets above a certain size. Currently, I plan to loop  
through the queue, retrieved from ThreadPoolExecutor.getQueue(), and  
call ThreadPoolExecutor.remove() on all low priority jobs.

Is this the best way to accomplish this? Will there be any  
concurrency issues here? It appears that if I remove a job that has  
already been executed, the method will simply return false.

Thanks for any ideas,


More information about the Concurrency-interest mailing list