yangxu998 / guava-libraries

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

Expiring map from MapMaker reports total size of the map not the current size #686

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have the following

Map<String,Lock> locks = new MapMaker()
           .concurrencyLevel(4)
           .expireAfterWrite(5, TimeUnit.MINUTES)
           .makeComputingMap(
               new Function<String, Lock>()
               {
                 public Lock apply(String key)
                 {
                   return new ReentrantLock();
                 }
               });

After adding entries and waiting long enough that the entries are expired 
calling locks.size() seems to return the size of the Map at its greatest size 
not the current size of the Map.

Original issue reported on code.google.com by craig.skinfill on 11 Aug 2011 at 5:21

GoogleCodeExporter commented 9 years ago
The size of the map will only be updated on writes, or on occasional reads. So 
if you stop using the map it is true that its size will be inaccurate.

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

GoogleCodeExporter commented 9 years ago
Note that Cache.cleanUp can now help with this problem.

Original comment by yrfselrahc@gmail.com on 2 Sep 2011 at 11:22

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