Class RunnableManager
- java.lang.Object
-
- org.eclipse.emf.ecp.view.internal.table.swt.RunnableManager
-
public class RunnableManager extends java.lang.Object
A utility class that is capable of maintaining the running state of a
Runnable
, i.e. frequent calls of theexecuteAsync(Runnable)
with long runningRunnable
s will not result in eachRunnable
being called. This is useful, for instance, if the sameRunnable
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RunnableManager.BackgroundStage
An optional mix-in interface for aRunnable
scheduled on theRunnableManager
that should be run in a background thread and which produces a subsequent stage for further execution.
-
Constructor Summary
Constructors Constructor Description RunnableManager(org.eclipse.swt.widgets.Display display)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
executeAsync(java.lang.Runnable runnable)
Execute the givenRunnable
viaDisplay.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, java.util.concurrent.TimeUnit unit)
Wait until no task is running or the giventime
elapses.
-
-
-
Method Detail
-
executeAsync
public void executeAsync(java.lang.Runnable runnable)
Execute the givenRunnable
viaDisplay.asyncExec(Runnable)
.- Parameters:
runnable
- theRunnable
to be executed asynchronously
-
getDisplay
public org.eclipse.swt.widgets.Display getDisplay()
- Returns:
- the display
-
isRunning
public boolean isRunning()
Query whether a runnable is in progress (asynchronously) on the display thread. The implication is that posting a new runnable at this instant would be redundant.- Returns:
true
if a runnable is currently running on the display thread or waiting to run on the display thread;false
, otherwise- Since:
- 1.20
-
waitForIdle
public final void waitForIdle() throws java.lang.InterruptedException
Wait until no task is running. Returns immediately if there is currently no task running.- Throws:
java.lang.InterruptedException
- if interrupted while waiting- Since:
- 1.21
-
waitForIdle
public final boolean waitForIdle(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
Wait until no task is running or the giventime
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.- Parameters:
time
- the amount of time to wait, or a non-positive amount to wait indefinitely as inwaitForIdle()
unit
- the unit of measure of thetime
to wait- Returns:
true
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)- Throws:
java.lang.InterruptedException
- if interrupted while waiting- Since:
- 1.21
-
-