public class RunOnce extends java.lang.Object implements RunnableOnce
Runnable
.
When run()
is called initially, it is delegated to Runnable.run()
, and
subsequent calls to run()
are be ignored (i.e. they do not result in a call to Runnable.run()
).
The method hasRun()
can be used to determine whether or not run()
has been called.
The reset()
method can be called to re-enable run()
to make another one-time call to
Runnable.run()
).Modifier and Type | Field and Description |
---|---|
private boolean |
has_run |
private java.lang.Runnable |
inner |
Constructor and Description |
---|
RunOnce() |
RunOnce(java.lang.Runnable innerRunnable) |
Modifier and Type | Method and Description |
---|---|
boolean |
hasRun()
Indicates whether
run() has been called. |
void |
mockRun()
Fakes a call to run.
|
void |
reset()
Resets the internal state of the RunnableOnce instance, so
run() can be called again,
even if it has already been called once. |
void |
run()
When an object implementing interface
Runnable is used
to create a thread, starting the thread causes the object's
run method to be called in that separately executing
thread. |
public RunOnce()
public RunOnce(java.lang.Runnable innerRunnable)
public boolean hasRun()
run()
has been called.hasRun
in interface RunnableOnce
run()
has already been called. This can be reset by a call to reset()
.public void mockRun()
public void reset()
run()
can be called again,
even if it has already been called once.reset
in interface RunnableOnce
public void run()
Runnable
is used
to create a thread, starting the thread causes the object's
run
method to be called in that separately executing
thread.
The general contract of the method run
is that it may
take any action whatsoever.
run
in interface java.lang.Runnable
Thread.run()