Class TickingThread

java.lang.Object
com.hypixel.hytale.server.core.util.thread.TickingThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
World, WorldMapManager

public abstract class TickingThread extends Object implements Runnable
  • Field Details

    • NANOS_IN_ONE_MILLI

      public static final int NANOS_IN_ONE_MILLI
      See Also:
    • NANOS_IN_ONE_SECOND

      public static final int NANOS_IN_ONE_SECOND
      See Also:
    • TPS

      public static final int TPS
      The number of ticks per second.
      See Also:
    • SLEEP_OFFSET

      public static long SLEEP_OFFSET
      Used to compensate for Thread.sleep being non-precise, we allow a small buffer to do a busy wait to ensure ticking accuracy.
  • Constructor Details

    • TickingThread

      public TickingThread(String threadName)
    • TickingThread

      public TickingThread(String threadName, int tps, boolean daemon)
  • Method Details

    • run

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

      @Nonnull public CompletableFuture<Void> start()
    • interrupt

      public boolean interrupt()
    • stop

      public void stop()
      Stops the thread and waits until it ends, or until it is abandoned after getAbandonTimeoutMillis(). Called from the ticking thread itself, it only requests the stop: the shutdown hook runs once the current tick returns.
      See Also:
    • stopAsync

      @Nonnull public CompletableFuture<Void> stopAsync()
      Stops the thread without blocking the caller. A dedicated thread waits for the run to end and abandons it after getAbandonTimeoutMillis(), exactly like stop() called from another thread. That holds when called from the ticking thread too.
      Returns:
      a future that completes once the shutdown hook of the run has returned, which can be later than an abandon. It completes exceptionally if the shutdown hook throws. Never join it from the ticking thread. The hook normally runs after the current tick returns, but after an abandon it runs on the stopper thread while the stuck tick is still blocked.
    • setTps

      public void setTps(int tps)
    • getTps

      public int getTps()
    • getTickStepNanos

      public int getTickStepNanos()
    • getBufferedTickLengthMetricSet

      public HistoricMetric getBufferedTickLengthMetricSet()
    • clearMetrics

      public void clearMetrics()
    • debugAssertInTickingThread

      public void debugAssertInTickingThread()
      Note: This doesn't fail if the thread has been shutdown. This is due to the timeout code in the stop() method, under normal conditions stopping the thread will succeed and so nothing will be running on the world thread to be able to call this.
    • isInThread

      public boolean isInThread()
    • isStarted

      public boolean isStarted()
    • getPossibleFailureCause

      @Nullable public PluginIdentifier getPossibleFailureCause()
    • getFailureException

      @Nullable public Throwable getFailureException()