Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. private static final EventBus INSTANCE;
  2.  
  3. static {
  4. // There should be just one system class loader object in the whole JVM.
  5. synchronized (ClassLoader.getSystemClassLoader()) {
  6. // The key is a String, because the .class object would be different across classloaders.
  7. final EventBus singleton = (EventBus) System.getProperties().get(EventBus.class.getName());
  8.  
  9. // Some other class loader loaded MessageBus earlier.
  10. if (singleton != null) {
  11. INSTANCE = singleton;
  12. } else {
  13. // Otherwise this classloader is the first one, let's create a singleton.
  14. // Make sure not to do any locking within this.
  15. INSTANCE = new EventBus();
  16. System.getProperties().put(EventBus.class.getName(), INSTANCE);
  17. }
  18. }
  19. }
  20.  
  21. public static EventBus getInstance() {
  22. return INSTANCE;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement