|
Best way to remove a scheduled task with ScheduledThreadPoolExecutor: msg#00008java.jsr.166-concurrency
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(); while (it.hasNext()) { 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 ... Many thanks! Bob _______________________________________________ Concurrency-interest mailing list Concurrency-interest@xxxxxxxxxxxxxxxxxxxx http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Extending with an exposed lock?, Moran Avigdor |
|---|---|
| Next by Date: | Re: Best way to remove a scheduled task with ScheduledThreadPoolExecutor, Holger Hoffstätte |
| Previous by Thread: | SwingWorker & allowCoreThreadsTimeout, Ernst, Matthias |
| Next by Thread: | Re: Best way to remove a scheduled task with ScheduledThreadPoolExecutor, Holger Hoffstätte |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |