Class AtmostOneTaskExecutor<V>
- java.lang.Object
-
- jenkins.util.AtmostOneTaskExecutor<V>
-
public class AtmostOneTaskExecutor<V> extends Object
Executor
-like class that executes a single task repeatedly, in such a way that a single execution can cover multiple pending queued requests.This is akin to doing laundry — when you put a dirty cloth into the laundry box, you mentally "schedule" a laundry task, regardless of whether there already is some cloths in the box or not. When you later actually get around doing laundry, you wash all the dirty cloths in the box, not just your cloths. And if someone brings more dirty cloths while a washer and dryer are in operation, the person has to mentally "schedule" the task and run the machines another time later, as the current batch is already in progress.
Since this class collapses multiple submitted tasks into just one run, it only makes sense when everyone submits the same task. Thus
submit()
method does not takeCallable
as a parameter, instead you pass that in the constructor.Implementation
This instance has two independent states. One is
pending
, which indicates that the task execution is requested but not yet scheduled. The other isinprogress
, which indicates that the task execution is scheduled but not yet completed.All the internal state transition is guarded by the monitor of 'this'.
pending
is non-null only ifinprogress
is non-null.- Author:
- Kohsuke Kawaguchi
- See Also:
AtmostOneThreadExecutor
-
-
Constructor Summary
Constructors Constructor Description AtmostOneTaskExecutor(Callable<V> task)
AtmostOneTaskExecutor(ExecutorService base, Callable<V> task)
-