Class LeastWorstDelay


  • public class LeastWorstDelay
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      LeastWorstDelay()  
    • Method Summary

      Modifier and Type Method Description
      static void debugDelayAsIfFor​(long nanos)  
      static void delayAsIfFor​(long nanos)
      We wish for the JVM to inline this.
      void delayAsIfUntil​(long targetNanoTime)
      This method has a quirky name, because it does something a bit quirky.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

    • Constructor Detail

      • LeastWorstDelay

        public LeastWorstDelay()
    • Method Detail

      • delayAsIfFor

        public static void delayAsIfFor​(long nanos)
        We wish for the JVM to inline this. This method tries to block a thread for a period of time, with a balance of accuracy and calling overhead. It does this by estimating the best way to block according to the time to block for and some knowledge of how much overhead and accuracy each method of blocking has. It's not perfect, but it is marginally better than a CPU burning busy wait or a throughput killing sleep right in the middle of every single thread. A better implementation would use sparse sampling of effective accuracy and feedback into the offsets, to deal with variability in CPU availability.
        Parameters:
        nanos - nanoseconds to delay for
      • debugDelayAsIfFor

        public static void debugDelayAsIfFor​(long nanos)
      • delayAsIfUntil

        public void delayAsIfUntil​(long targetNanoTime)
        This method has a quirky name, because it does something a bit quirky. Inject delay, but do not await a condition that the delay is accurate according to the real time clock. Return the presumed real time clock value after the delay. This method is meant to provide lightweight delay when accuracy is not as important as efficiency, and where the jitter in the result will not result in an error that accumulates. Users must be careful to avoid using this method in other scenarios.
        Parameters:
        targetNanoTime - The system nanos that the delay should attempt to return at. perfect accuracy, which doesn't happen