Contents
Class TickingThread
java.lang.Object
com.hypixel.hytale.server.core.util.thread.TickingThread
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
World, WorldMapManager
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic longUsed to compensate for Thread.sleep being non-precise, we allow a small buffer to do a busy wait to ensure ticking accuracy.static final intThe number of ticks per second. -
Constructor Summary
ConstructorsConstructorDescriptionTickingThread(String threadName) TickingThread(String threadName, int tps, boolean daemon) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidNote: This doesn't fail if the thread has been shutdown.intintgetTps()booleanbooleanbooleanvoidrun()voidsetTps(int tps) start()voidstop()Stops the thread and waits until it ends, or until it is abandoned aftergetAbandonTimeoutMillis().Stops the thread without blocking the caller.
-
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 TPSThe number of ticks per second.- See Also:
-
SLEEP_OFFSET
public static long SLEEP_OFFSETUsed 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
-
TickingThread
-
-
Method Details
-
run
-
start
-
interrupt
public boolean interrupt() -
stop
public void stop()Stops the thread and waits until it ends, or until it is abandoned aftergetAbandonTimeoutMillis(). Called from the ticking thread itself, it only requests the stop: the shutdown hook runs once the current tick returns.- See Also:
-
stopAsync
Stops the thread without blocking the caller. A dedicated thread waits for the run to end and abandons it aftergetAbandonTimeoutMillis(), exactly likestop()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
-
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 thestop()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
-
getFailureException
-