[concurrency-interest] Frequently canceled timers
rjohns at nortel.com
Fri Jan 25 14:56:08 EST 2008
Doug Lea wrote:
> Richard Johns wrote:
>> I have an application that retransmits messages when they don't get a
>> timely response . Usually, of course, that's not necessary and their
>> timers are canceled. This is a traffic generator so message rate is
>> high and we need to remove the canceled timers.
>> Is there a timer implementation that efficiently cleans up canceled
>> timers? DelayQueue uses a binary heap so it's very fast otherwise,
>> but it uses a sequential search for remove().
>> ScheduledThreadPoolExecutor uses DelayQueue, and Timer also uses a
>> binary heap.
> Sorry for not paying attention to this before others replied...
> Last september, we put out revised version of ScheduledThreadPoolExecutor
> that uses an internal variant of DelayQueue that includes fast eager
> cleanup on cancel. This isn't scheduled to get out until Java7 though.
> Which looks like it might be a while.
> And even then. because of compatibility concerns, fast cleanup won't
> be default enabled -- see method setRemoveOnCancelPolicy(boolean).
> (Although hopefully this will be reconsidered later.)
> But until then you may be able to use or adapt our version in
> CVS, that relies also on updated version of ThreadPoolExecutor
> that you can also get from CVS.
Perfect! (Well, except for the "Java7" part.) Thanks, I'll use this.
More information about the Concurrency-interest