public abstract class Memoizer<A,V> extends Object implements Computable<A,V>
FutureTask
to force synchronization only on tasks
waiting for the same computation. This is based on Java Concurrency in
Practice, page 108.
Concrete implementations MUST provide a means to limit the size of the
cache
. Because the cache
is unbounded, it will just take on
more and more memory as new results are computed. This could be handled by
imposing a capacity constraint on the cache, by the use of
WeakReference
s if they can be made to stand for the specific
computation to be performed, or by the use of a timeout on the cache entries.
Modifier and Type | Field and Description |
---|---|
protected ConcurrentMap<A,Future<V>> |
cache
Cache accumulates results.
|
Constructor and Description |
---|
Memoizer(Computable<A,V> c) |
protected final ConcurrentMap<A,Future<V>> cache
public Memoizer(Computable<A,V> c)
public V compute(A arg) throws InterruptedException
compute
in interface Computable<A,V>
InterruptedException
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.