Compare commits

..

No commits in common. "866a5471140586047d965df092d0ce64d7c89ecb" and "b915a5c4901d34a4ee4f21a0701573381109e4e7" have entirely different histories.

View File

@ -52,18 +52,26 @@ public final class EventBus {
*/ */
public static final int DEFAULT_PRIORITY = 100; public static final int DEFAULT_PRIORITY = 100;
private static final EventBus singletonInstance = new EventBus(); private static volatile EventBus singletonInstance;
private static final Logger logger = System.getLogger(EventBus.class.getName()); private static final Logger logger = System.getLogger(EventBus.class.getName());
/** /**
* Returns the default event bus, which is a statically initialized singleton instance. * Produces a singleton instance of the event bus. It is lazily initialized on the first call.
* *
* @return the default event bus * @return a singleton instance of the event bus.
* @since 0.0.2 * @since 0.0.2
*/ */
public static EventBus getInstance() { public static EventBus getInstance() {
return singletonInstance; EventBus instance = singletonInstance;
if (instance == null)
synchronized (EventBus.class) {
if ((instance = singletonInstance) == null) {
logger.log(Level.DEBUG, "Initializing singleton event bus instance");
instance = singletonInstance = new EventBus();
}
}
return instance;
} }
private final Map<Class<?>, TreeSet<EventHandler>> bindings = private final Map<Class<?>, TreeSet<EventHandler>> bindings =