- java.lang.Object
-
- com.aoapps.concurrent.ConcurrencyReducer<R>
-
public class ConcurrencyReducer<R> extends Object
Limits the concurrency to a resource. When a second thread tries to access the same resource as a previous thread, it will share the results that are obtained by the previous thread.
-
-
Constructor Summary
Constructors Constructor Description ConcurrencyReducer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RexecuteSerialized(Callable<? extends R> callable)Executes a callable at most once.
-
-
-
Method Detail
-
executeSerialized
public R executeSerialized(Callable<? extends R> callable) throws InterruptedException, ExecutionException
Executes a callable at most once. If a callable is in the process of being executed by a different thread, the current thread will wait and use the results obtained by the other thread.
Consider the following scenario:
- Thread A invokes MySQL: "CHECK TABLE example FAST QUICK"
- Thread B invokes MySQL: "CHECK TABLE example FAST QUICK" before Thread A has finished
- Thread B wait for results determined by Thread A
- Thread A completes, passes results to Thread B
- Threads A and B both return the results obtained only by Thread A
-
-