java.lang.Object
org.elasticsearch.common.util.concurrent.RunOnce
All Implemented Interfaces:
Runnable

public class RunOnce extends Object implements Runnable
Runnable that prevents running its delegate more than once.

Crucially, this drops the reference to the provided delegate as soon as it executes, allowing it and its dependencies to be GCd even though the small RunOnce wrapper might remain reachable in a collection of pending-execution callbacks somewhere.

  • Constructor Details

    • RunOnce

      public RunOnce(Runnable delegate)
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
    • hasRun

      public boolean hasRun()
      true if the RunOnce has been executed once.
    • toString

      public String toString()
      Overrides:
      toString in class Object