Package jenkins.util

Class 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 take Callable 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 is inprogress, 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 if inprogress is non-null.

    Author:
    Kohsuke Kawaguchi
    See Also:
    AtmostOneThreadExecutor
    • Constructor Detail

      • AtmostOneTaskExecutor

        public AtmostOneTaskExecutor​(Callable<V> task)
    • Method Detail

      • submit

        public Future<V> submit()