Java Reference
In-Depth Information
Listing 5.18. Memoizing Wrapper Using
FutureTask
.
Memoizer3
is vulnerable to this problem because a compound action (put-if-absent) is per-
the window of vulnerability in
Memoizer3
.
Caching a
Future
instead of a value creates the possibility of
cache pollution
: if a compu-
tation is cancelled or fails, future attempts to compute the result will also indicate cancella-
tion or failure. To avoid this,
Memoizer
removes the
Future
from the cache if it detects
that the computation was cancelled; it might also be desirable to remove the
Future
upon