Actually this is not going to work since removeEldestEntry is only
called when calling put on the map and even then it is only called once
for each put, disallowing dropping multiple expired entries at once.
I kicked LinkedHashMap around a couple of times to try and get this
working properly but gave up on it.
The simplest self-built solution is wrapping key/element pairs in
wrapper objects that also implements a doubly-linked list to represent
the queue and coupling that with a plain HashMap that maps key values to
the corresponding wrapper.
I have done this to create caches that makes elements expire if they
have been in the cache for too long or have not been retrieved for too
long. Naturally this can be done either implicitly at lookup time or
explicitly with some purgeExpiredEntries method that could be called
periodically even when not querying the cache.
There probably also are existing cache libraries that will do this for
you if you don't mind the dependency.
Silvio