Class RunnableManager
- java.lang.Object
-
- org.eclipse.emf.ecp.view.internal.table.swt.RunnableManager
-
public class RunnableManager extends java.lang.ObjectA utility class that is capable of maintaining the running state of a
Runnable, i.e. frequent calls of theexecuteAsync(Runnable)with long runningRunnables will not result in eachRunnablebeing called. This is useful, for instance, if the sameRunnableis submitted multiple times unnecessarily.If a runnable additionally implements the
RunnableManager.BackgroundStageinterface, 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 interfaceRunnableManager.BackgroundStageAn optional mix-in interface for aRunnablescheduled on theRunnableManagerthat 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 voidexecuteAsync(java.lang.Runnable runnable)Execute the givenRunnableviaDisplay.asyncExec(Runnable).org.eclipse.swt.widgets.DisplaygetDisplay()booleanisRunning()Query whether a runnable is in progress (asynchronously) on the display thread.voidwaitForIdle()Wait until no task is running.booleanwaitForIdle(long time, java.util.concurrent.TimeUnit unit)Wait until no task is running or the giventimeelapses.
-
-
-
Method Detail
-
executeAsync
public void executeAsync(java.lang.Runnable runnable)
Execute the givenRunnableviaDisplay.asyncExec(Runnable).- Parameters:
runnable- theRunnableto 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:
trueif 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.InterruptedExceptionWait 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.InterruptedExceptionWait until no task is running or the giventimeelapses. 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 thetimeto wait- Returns:
trueif on return there is no task running;falseon 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
-
-