[concurrency-interest] Best way to remove a scheduled task with ScheduledThreadPoolExecutor
syg6 at yahoo.com
Tue Oct 10 11:12:34 EDT 2006
Hello again all,
I am using a ScheduledThreadPoolExecutor to schedule Runnable tasks. I would like to be able to remove tasks as well. I see in the API that ScheduledThreadPoolExecutor has a remove() method which takes a Runnable as a parameter. Fantastic! How do I tell it which Runnable I want to remove?
I've tried getting the ScheduledThreadPoolExecutor's BlockingQueue and iterating over it:
BlockingQueue bq = stpe.getQueue();
MyRunnable mr = (MyRunnable)it.next();
but as soon as I call it.next() I get a ConcurrentModificationException. Yikes.
How else can I do this? Removing all of the elements (using drainTo()?) off the BlockingQueue and re-scheduling all of the remaining ScheduledThreadPoolExecutor tasks? This doesn't sound like a good idea ...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest