yangxu998 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

MapMaker document how to trigger global expiration & cleanup #681

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is a pretty hard thing to ask for since I suppose I'm using 
MapMaker#makeComputingMap more as a concurrency control mechanism than as a 
cache, but please bear with me.  It this falls out of your expected use cases 
then of course I'll understand.

This may be a duplicate of #608, depending on how you look at the problem.

(1) I have a computing map with an expiration, (2) the value objects hold 
references to a limited external resource -- think a database connection, and 
you'll have the right model -- and, (3) I use a MapEvictionListener to close 
the external resource.

MapMaker 100% fulfills its contract that items in the map are not visible after 
expiration, and eventually the eviction listener is called, but from external 
the policy appears non-deterministic because cleanup is (rightly) done by 
segment and (smartly) gated by things like DRAIN_THRESHOLD.

My workaround is to set concurrencyLevel(1) and then get a reference to 
MapMaker.Segment#cleanupRunnable (reflection) and schedule it.  (Yikes!!)  A 
hint in the javadoc about which methods may trigger global cleanup (size()??) 
would allow me to schedule a periodic call of those instead.  I don't advocate 
a public cleanup() method b/c I really like that MM returns vanilla 
ConcurrentMap

The assumptions built into MapMaker's implementation seem optimized for heavily 
used maps.  In my use case the map is heavily used for short periods, er, 
periodically, then falls idle.  So the heuristics are never triggered.

Thanks,
-dg

Oh, and BTW, I really do prefer the current mechanics to the old 
ExpirationTimer.  Bravo!

Original issue reported on code.google.com by gil...@gmail.com on 9 Aug 2011 at 7:40

GoogleCodeExporter commented 9 years ago
One option here is to expose a cleanupExecutor method.

Original comment by fry@google.com on 12 Aug 2011 at 2:16

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 1 Sep 2011 at 5:35

GoogleCodeExporter commented 9 years ago
woohoo!  Thanks.

Original comment by gil...@gmail.com on 6 Sep 2011 at 5:38

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09