MCPcopy Create free account
hub / github.com/dorkbox/SystemTray / runLater

Method runLater

src/dorkbox/systemTray/util/EventDispatch.java:49–70  ·  view source on GitHub ↗

Schedule an event to occur sometime in the future. We do not want to WAIT for a `runnable` to finish, because it is POSSIBLE that this runnable wants to perform actions on the SAME dispatch thread that called this, resulting in a deadlock. Because we cannot guarantee that this will never happen, we

(final Runnable runnable)

Source from the content-addressed store, hash-verified

47 * guarantee that this will never happen, we must always run this "in the future" as a queue - so that FIFO is obeyed.
48 */
49 public static
50 void runLater(final Runnable runnable) {
51 synchronized(EventDispatch.class) {
52 if (eventDispatchExecutor == null) {
53 if (insideDispatch) {
54 SystemTray.logger.error("Unable to create a new event dispatch, while executing within the same context.");
55 return;
56 }
57
58 shutdownLatch = new CountDownLatch(1);
59 eventDispatchExecutor = Executors.newSingleThreadExecutor(
60 new NamedThreadFactory("SystemTrayEventDispatch",
61 Thread.currentThread().getThreadGroup(), THREAD_PRIORITY, true));
62 }
63 }
64
65 eventDispatchExecutor.execute(()->{
66 insideDispatch = true;
67 runnable.run();
68 insideDispatch = false;
69 });
70 }
71
72 /**
73 * Shutdown the event dispatch at the end of our current dispatch queue

Callers 14

shutdownMethod · 0.95
addMethod · 0.95
removeMethod · 0.95
actionPerformedMethod · 0.95
actionPerformedMethod · 0.95
itemStateChangedMethod · 0.95
actionPerformedMethod · 0.95
actionPerformedMethod · 0.95
itemStateChangedMethod · 0.95
actionPerformedMethod · 0.95
actionPerformedMethod · 0.95
shutdownMethod · 0.95

Calls 1

runMethod · 0.45

Tested by 1

dispatchMethod · 0.64