commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Arun Thomas" <>
Subject RE: TimerMap
Date Mon, 24 Nov 2003 19:00:36 GMT
IMHO, if the intention is that this class should be used only in contexts (the specific cases)
that are _always_ aware of the implementation, then I would be -1 to implementing the Map
interface - even if the methods are the same.  I would also then change the interface to represent
only those methods that ought to be used in this context - put/get, removing values() and
keySet() in particular.  

On another point - any reason why TimerMapKey is public?

I still think it's something very useful!


-----Original Message-----
From: James Carman [] 
Sent: Monday, November 24, 2003 10:36 AM
To: 'Jakarta Commons Developers List'
Subject: RE: TimerMap

I wouldn't worry so much about the iterator issue.  Remember, this map implementation is to
be used in specific cases.  And, when somebody uses it, they should probably understand that
there are multiple threads modifying the map.  I would say that you can get by with a warning
in the JavaDoc on this one.  No need to get overly complicated here IMHO.  

-----Original Message-----
From: Arun Thomas [] 
Sent: Monday, November 24, 2003 1:24 PM
To: Jakarta Commons Developers List
Subject: RE: TimerMap

Seems like a cool idea....  However, I'm concerned about the following points in the implementation:

If the timer expires after an iterator on the keys or values is obtained, the underlying map
is modified directly - this means that the next access to the iterator (see HashMap javadoc)
will throw a ConcurrentModificationException.  To my mind, this makes iteration over this
map fairly difficult, particularly as many algorithms which use maps probably do use iterators
to access the data in the map.  A possible solution - provide wrapping implementations of
Set/Collection which return FilterIterators that filter out expired items during iteration
- only deleting those items after all existing iterators have completed iteration or have
been destroyed.  This gets complicated quickly, however.  

It seems (perhaps I'm missing something) to be overkill to synchronize all accesses to the
TimerMap.  I'm not quite sure why this is necessary - I don't think the implementation can
guarantee that an object will be expired at the instant the timer runs out - I don't believe
TimerTask provides this guarantee.  Therefore, the synchronization seems to be unneeded -
the expired object will be removed "soon" after the expiry time is reached.  


-----Original Message-----
From: Joseph Rosenblum [] 
Sent: Sunday, November 23, 2003 11:04 PM
Subject: TimerMap

Commons Developers,

The attached class is a very simple implementation of the java.util.Map 
interface that gives each key a TTL (time to live) in the map. I've 
found this extremely useful as a backing store for certain types of 
caches (where you want to expire items based on time in cache, as 
opposed to LRU, etc..) and for tracking services that I want check the 
availability of. It's called TimerMap and takes a long TTL in the 

I'd love to donate this code to the commons, please let me know if you 
find it useful.


Joseph Rosenblum | 25th Street Networks
Easy, Reliable Web Hosting @

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message