java.lang.Object
org.autogui.swing.util.SwingDeferredRunner
a task runner in the event dispatching thread without blocking
try {
Object ret = SwingDeferredRunner.run(task);
if (ret instanceof SwingDeferredRunner.TaskResultFuture) {
Future<Object> f = ((TaskResultFuture) ret).getFuture();
...
} else {
...
}
} catch(Throwable errorWhileTask) { ... }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacea function interface under the event dispatching threadstatic classa result for a thrown exception:SwingDeferredRunner.TaskResultFuturereturn the value if the task failed with an exceptionstatic classa incomplete result -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic ExecutorServicestatic ThreadLocal<Boolean> protected Supplier<ExecutorService> protected LinkedBlockingQueue<Object> protected SwingDeferredRunner.Taskstatic Object -
Constructor Summary
ConstructorsConstructorDescriptionSwingDeferredRunner(Supplier<ExecutorService> futureFactory, SwingDeferredRunner.Task task) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidstatic ExecutorServicestatic voidrun the task bySwingUtilities.invokeAndWait(Runnable)with wrapping byScheduledTaskRunner.withDepthInfo(String, Runnable)andScheduledTaskRunner.depthRunner(Runnable)static voidrun the task bySwingUtilities.invokeLater(Runnable)with wrapping byScheduledTaskRunner.depthRunner(Runnable)static booleanstatic booleanrun()execute the specified task on the event dispatching thread and return the result.static Objectrun(SwingDeferredRunner.Task task)
-
Field Details
-
result
-
task
-
futureFactory
-
dispatchedFromEventThread
-
defaultService
-
TASK_RESULT_NULL
-
-
Constructor Details
-
SwingDeferredRunner
-
-
Method Details
-
isEventThreadOrDispatchedFromEventThread
public static boolean isEventThreadOrDispatchedFromEventThread() -
isDispatchedFromEventThread
public static boolean isDispatchedFromEventThread() -
invokeLater
run the task bySwingUtilities.invokeLater(Runnable)with wrapping byScheduledTaskRunner.depthRunner(Runnable)- Parameters:
r- the task
-
invokeAndWait
run the task bySwingUtilities.invokeAndWait(Runnable)with wrapping byScheduledTaskRunner.withDepthInfo(String, Runnable)andScheduledTaskRunner.depthRunner(Runnable)- Parameters:
r- the task- Throws:
InterruptedException- from invokeWaitInvocationTargetException- from invokeWait
-
getDefaultService
-
cleanDefaultService
public static void cleanDefaultService() -
run
- Throws:
Throwable
-
run
execute the specified task on the event dispatching thread and return the result. if the current thread is the event dispatching thread, then it runs immediately. otherwise, submit the task to the event dispatching thread, and wait a little while and return a future value if it is not completed.- Returns:
- the result of the task (nullable) if no-delaying,
or
SwingDeferredRunner.TaskResultFuturesubmitted to the futureFactory - Throws:
Throwable- if the task throws an exception without delay, then it is thrown
-