Class ThreadUtils
java.lang.Object
io.github.syst3ms.skriptparser.util.ThreadUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ExecutorServiceBuilds a new thread using anExecutorService, allowing various utility methods.static ScheduledExecutorServiceBuilds a new thread using anScheduledExecutorService, allowing various utility methods.static voidRun certain code once after a certain delay.static voidRun certain code once on a separate thread.static voidrunPeriodically(Runnable code, Duration duration) Runs certain code periodically.static voidrunPeriodically(Runnable code, Duration initialDelay, Duration duration) Runs certain code periodically.static voidrunPeriodicallyBounded(Runnable code, Duration duration, Duration maxTime) Runs certain code periodically but with a final bound.static voidrunPeriodicallyBounded(Runnable code, Duration initialDelay, Duration duration, Duration maxTime) Runs certain code periodically but with a final bound.
-
Constructor Details
-
ThreadUtils
public ThreadUtils()
-
-
Method Details
-
runAsync
Run certain code once on a separate thread. The thread is shut down after the code ran.- Parameters:
code- the runnable that needs to be executed
-
runAfter
-
runPeriodically
-
runPeriodically
-
runPeriodicallyBounded
-
runPeriodicallyBounded
public static void runPeriodicallyBounded(Runnable code, Duration initialDelay, Duration duration, Duration maxTime) Runs certain code periodically but with a final bound.- Parameters:
code- the runnable that needs to be executedinitialDelay- the initial delayduration- the delaymaxTime- the duration this thread will be opened in milliseconds
-
buildAsync
Builds a new thread using anExecutorService, allowing various utility methods.- Returns:
- the created thread
-
buildPeriodic
Builds a new thread using anScheduledExecutorService, allowing various utility methods.- Returns:
- the created thread
-