public class RunnableManager extends Object
A utility class that is capable of maintaining the running
state of a Runnable
, i.e. frequent calls of the executeAsync(Runnable)
with long running Runnable
s will not result in each Runnable
being called.
This is useful, for instance, if the same Runnable
is
submitted multiple times unnecessarily.
If a runnable additionally implements the RunnableManager.BackgroundStage
interface, then
it will be invoked on a background thread and when complete will be asked to
provide a subsequent stage to execute.
This may similarly be a background stage, iterating the process, or may be a terminal
runnable that then is posted on the UI thread to update the UI.
Modifier and Type | Class and Description |
---|---|
static interface |
RunnableManager.BackgroundStage
An optional mix-in interface for a
Runnable scheduled on the
RunnableManager that should be run in a background thread and which
produces a subsequent stage for further execution. |
Constructor and Description |
---|
RunnableManager(org.eclipse.swt.widgets.Display display)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
executeAsync(Runnable runnable)
Execute the given
Runnable via Display.asyncExec(Runnable) . |
org.eclipse.swt.widgets.Display |
getDisplay() |
boolean |
isRunning()
Query whether a runnable is in progress (asynchronously) on the display thread.
|
void |
waitForIdle()
Wait until no task is running.
|
boolean |
waitForIdle(long time,
TimeUnit unit)
Wait until no task is running or the given
time elapses. |
public RunnableManager(org.eclipse.swt.widgets.Display display)
display
- the Display
that is used to submit a runnablepublic void executeAsync(Runnable runnable)
Runnable
via Display.asyncExec(Runnable)
.runnable
- the Runnable
to be executed asynchronouslypublic org.eclipse.swt.widgets.Display getDisplay()
public boolean isRunning()
true
if a runnable is currently running on the display thread
or waiting to run on the display thread; false
, otherwisepublic final void waitForIdle() throws InterruptedException
InterruptedException
- if interrupted while waitingpublic final boolean waitForIdle(long time, TimeUnit unit) throws InterruptedException
time
elapses.
Returns immediately if there is currently no task running. Note that if called on the
UI thread, then the actual wait time in case of time-out can be longer than requested
because of UI event queue processing.time
- the amount of time to wait, or a non-positive amount to wait indefinitely
as in waitForIdle()
unit
- the unit of measure of the time
to waittrue
if on return there is no task running; false
on time-out
(which does not mean that since the time-out occurred the manager did not become idle)InterruptedException
- if interrupted while waitingCopyright © 2020. All rights reserved.