public static void closeDisplay(long handle) { synchronized (globalLock) { final NamedDisplay namedDpy = (NamedDisplay) openDisplayMap.remove(handle); if (null == namedDpy) { X11Util.dumpPendingDisplayConnections(); throw new RuntimeException( "X11Util.Display: Display(0x" + Long.toHexString(handle) + ") with given handle is not mapped. Thread " + Thread.currentThread().getName()); } if (namedDpy.getHandle() != handle) { X11Util.dumpPendingDisplayConnections(); throw new RuntimeException( "X11Util.Display: Display(0x" + Long.toHexString(handle) + ") Mapping error: " + namedDpy + ". Thread " + Thread.currentThread().getName()); } namedDpy.removeRef(); if (!openDisplayList.remove(namedDpy)) { throw new RuntimeException("Internal: " + namedDpy); } if (markAllDisplaysUnclosable) { // if set-mark 'slipped' this one .. just to be safe! namedDpy.setUncloseable(true); } if (!namedDpy.isUncloseable()) { XCloseDisplay(namedDpy.getHandle()); pendingDisplayList.remove(namedDpy); } else { // for reuse X11Lib.XSync(namedDpy.getHandle(), true); // flush output buffer and discard all events reusableDisplayList.add(namedDpy); } if (DEBUG) { System.err.println( "X11Util.Display: Closed (real: " + (!namedDpy.isUncloseable()) + ") " + namedDpy + ". Thread " + Thread.currentThread().getName()); } } }