Class EatWhatYouKill

  • All Implemented Interfaces:
    java.lang.Runnable, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, ExecutionStrategy

    @ManagedObject("eat what you kill execution strategy")
    public class EatWhatYouKill
    extends ContainerLifeCycle
    implements ExecutionStrategy, java.lang.Runnable

    A strategy where the thread that produces will run the resulting task if it is possible to do so without thread starvation.

    This strategy preemptively dispatches a thread as a pending producer, so that when a thread produces a task it can immediately run the task and let the pending producer thread take over production. When operating in this way, the sub-strategy is called Execute Produce Consume (EPC).

    However, if the task produced uses the Invocable API to indicate that it will not block, then the strategy will run it directly, regardless of the presence of a pending producer thread and then resume production after the task has completed. When operating in this pattern, the sub-strategy is called ProduceConsume (PC).

    If there is no pending producer thread available and if the task has not indicated it is non-blocking, then this strategy will dispatch the execution of the task and immediately continue production. When operating in this pattern, the sub-strategy is called ProduceExecuteConsume (PEC).

    • Field Detail

      • LOG

        private static final Logger LOG
      • _pcMode

        private final java.util.concurrent.atomic.LongAdder _pcMode
      • _picMode

        private final java.util.concurrent.atomic.LongAdder _picMode
      • _pecMode

        private final java.util.concurrent.atomic.LongAdder _pecMode
      • _epcMode

        private final java.util.concurrent.atomic.LongAdder _epcMode
      • _executor

        private final java.util.concurrent.Executor _executor
      • _pending

        private boolean _pending
    • Constructor Detail

    • Method Detail

      • dispatch

        public void dispatch()
        Description copied from interface: ExecutionStrategy

        Initiates (or resumes) the task production and consumption.

        This method guarantees that the task is never run by the thread that called this method.

        TODO review the need for this (only used by HTTP2 push)
        Specified by:
        dispatch in interface ExecutionStrategy
        See Also:
        ExecutionStrategy.produce()
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • tryProduce

        private void tryProduce​(boolean wasPending)
      • doProduce

        private boolean doProduce​(boolean nonBlocking)
      • runTask

        private void runTask​(java.lang.Runnable task)
      • invokeTask

        private void invokeTask​(java.lang.Runnable task)
      • produceTask

        private java.lang.Runnable produceTask()
      • execute

        private void execute​(java.lang.Runnable task)
      • toStringLocked

        public java.lang.String toStringLocked()
      • getString

        private void getString​(java.lang.StringBuilder builder)
      • getState

        private void getState​(java.lang.StringBuilder builder)