Class RunOnce
java.lang.Object
com.tccc.kos.commons.util.concurrent.RunOnce
Runnable object that wraps a single function that will never be called concurrently and once
returning true, will never be called again unless reset. This handles a common pattern when a
startup process requires some operation to be run exactly once per boot or once per cycle of
some process. This eliminates the need to track state and coordinate concurrency.
- Since:
- 1.9
- Version:
- 2025-10-26
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionRunOnce(RunOnce.RunOnceCallback callback) Create a newRunOncefor the specified callback. -
Method Summary
-
Constructor Details
-
RunOnce
Create a newRunOncefor the specified callback. The callback can be triggered by callingrun()to run it inline orexecute()to run it on another thread. Once the callback returns true, it will never be called again unlessreset()is called.- Parameters:
callback- the callback to run successfuly one time
-
-
Method Details
-
run
public void run()Run the callback from the calling thread. If the callback is already running in another thread, this will return immediately and the callback will be queued to run again when the current callback ends. -
execute
public void execute()Run the callback in another thread. -
reset
public void reset()Allow the callback to be run again. -
isDone
public boolean isDone()Return true if the callback as been run successfully
-