/** * Cleanup resources. * * <p>Called by {@link NativeWindowFactory#shutdown()} * * @see ToolkitProperties */ public static void shutdown() { if (isInit) { synchronized (X11Util.class) { if (isInit) { final boolean isJVMShuttingDown = NativeWindowFactory.isJVMShuttingDown(); if (DEBUG || ((openDisplayMap.size() > 0 || reusableDisplayList.size() > 0 || pendingDisplayList.size() > 0) && (reusableDisplayList.size() != pendingDisplayList.size() || !markAllDisplaysUnclosable))) { System.err.println( "X11Util.Display: Shutdown (JVM shutdown: " + isJVMShuttingDown + ", open (no close attempt): " + openDisplayMap.size() + "/" + openDisplayList.size() + ", reusable (open, marked uncloseable): " + reusableDisplayList.size() + ", pending (open in creation order): " + pendingDisplayList.size() + ")"); if (DEBUG) { Thread.dumpStack(); } if (openDisplayList.size() > 0) { X11Util.dumpOpenDisplayConnections(); } if (DEBUG) { if (reusableDisplayList.size() > 0 || pendingDisplayList.size() > 0) { X11Util.dumpPendingDisplayConnections(); } } } // Only at JVM shutdown time, since AWT impl. seems to // dislike closing of X11 Display's (w/ ATI driver). if (isJVMShuttingDown) { synchronized (globalLock) { isInit = false; closePendingDisplayConnections(); openDisplayList.clear(); reusableDisplayList.clear(); pendingDisplayList.clear(); openDisplayMap.clear(); displayXineramaEnabledMap.clear(); shutdown0(); } } } } } }
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()); } } }