Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final EventBus INSTANCE;
- static {
- // There should be just one system class loader object in the whole JVM.
- synchronized (ClassLoader.getSystemClassLoader()) {
- // The key is a String, because the .class object would be different across classloaders.
- final EventBus singleton = (EventBus) System.getProperties().get(EventBus.class.getName());
- // Some other class loader loaded MessageBus earlier.
- if (singleton != null) {
- INSTANCE = singleton;
- } else {
- // Otherwise this classloader is the first one, let's create a singleton.
- // Make sure not to do any locking within this.
- INSTANCE = new EventBus();
- System.getProperties().put(EventBus.class.getName(), INSTANCE);
- }
- }
- }
- public static EventBus getInstance() {
- return INSTANCE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement