Updating selfpopulatingcache example
CHM only fails the computing thread and allows the waiting threads to retry the computation. ( placeholder nodes that are populated after the computation has completed.In other implementations the waiting threads rethrow the exception and don't recompute. refresh) method may also be useful, though can be adequately supplied by usages. This version is much more amenable to upcoming support for aggregate parallel operations (including, already, method "compute If Absent' using a stand-in Mapping Function type). Thanks, but the plain version of CHM doesn't itself deal with Futures (aka placeholders).Even though this is private-method doc, I suggest "Implementation of compute If Absent". The more arbitrary decision is what to do if the computation returns null. compute(k, f) vs compute If Absent(k, f)) is easy to add, and provides a symmetical API to the two forms of put, and has some uses, so I added it. Results vary across different kinds of tests, depending on operation mixes, key types, temporal locality of lookups, etc, so I can't give a better answer than: each is sometimes faster (and sometimes by a lot) than the other.Compute If Absent could be defined to throw Null Pointer Exception, but this is a fairly heavy response to the case where it turns out that the key has no mapping, since a null return provides the same information. But the previous scalability limits due to use of Segments is now gone, so the performance differences now mostly reflect other design tradeoffs.
This can be useful for cache invalidation where it is preferred vs. a user's equals() function that attempts to invoke CHM only fails It is -- an exception leaves mapping untouched.