Added shutdown to Event Dispatch
This commit is contained in:
parent
0b53d5388f
commit
f44374d11d
|
@ -1,24 +1,37 @@
|
||||||
package dorkbox.systemTray.util;
|
package dorkbox.systemTray.util;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import dorkbox.util.NamedThreadFactory;
|
import dorkbox.util.NamedThreadFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds events to a single thread event dispatch, so that regardless of OS, all event callbacks happen on the same thread -- which is NOT
|
* Adds events to a single thread event dispatch, so that regardless of OS, all event callbacks happen on the same thread -- which is NOT
|
||||||
* the GTK/AWT/SWING event dispatch thread. There can be odd peculariaties across on GTK with how AWT/SWING react with the GTK Event
|
* the GTK/AWT/SWING event dispatch thread. There can be ODD peculiarities across on GTK with how AWT/SWING react with the GTK Event
|
||||||
* Dispatch Thread.
|
* Dispatch Thread.
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
class EventDispatch {
|
class EventDispatch {
|
||||||
private static final Executor eventDispatchExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("SystemTray", true));
|
private static ExecutorService eventDispatchExecutor = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule an event to occur sometime in the future.
|
* Schedule an event to occur sometime in the future.
|
||||||
*/
|
*/
|
||||||
public static
|
public static synchronized
|
||||||
void runLater(Runnable runnable) {
|
void runLater(Runnable runnable) {
|
||||||
|
if (eventDispatchExecutor == null) {
|
||||||
|
eventDispatchExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("SystemTrayEventDispatch", false));
|
||||||
|
}
|
||||||
|
|
||||||
eventDispatchExecutor.execute(runnable);
|
eventDispatchExecutor.execute(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutdown the event dispatch
|
||||||
|
*/
|
||||||
|
public static synchronized
|
||||||
|
void shutdown() {
|
||||||
|
eventDispatchExecutor.shutdownNow();
|
||||||
|
eventDispatchExecutor = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user