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)
| 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 |