src/share/classes/sun/awt/AppContext.java

Print this page

        

*** 44,53 **** --- 44,54 ---- import java.beans.PropertyChangeListener; import sun.util.logging.PlatformLogger; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; + import java.util.concurrent.atomic.AtomicInteger; /** * The AppContext is a table referenced by ThreadGroup which stores * application service instances. (If you are not writing an application * service, or don't know what one is, please do not use this class.)
*** 193,202 **** --- 194,205 ---- public boolean isDisposed() { return isDisposed; } static { + numAppContexts = new AtomicInteger(1); + // On the main Thread, we get the ThreadGroup, make a corresponding // AppContext, and instantiate the Java EventQueue. This way, legacy // code is unaffected by the move to multiple AppContext ability. AccessController.doPrivileged(new PrivilegedAction() { public Object run() {
*** 207,217 **** // Find the root ThreadGroup to construct our main AppContext currentThreadGroup = parentThreadGroup; parentThreadGroup = currentThreadGroup.getParent(); } mainAppContext = new AppContext(currentThreadGroup); - numAppContexts = 1; return mainAppContext; } }); } --- 210,219 ----
*** 220,230 **** * incremented at the beginning of the constructor, and decremented * at the end of dispose(). getAppContext() checks to see if this * number is 1. If so, it returns the sole AppContext without * checking Thread.currentThread(). */ ! private static volatile int numAppContexts; /* * The context ClassLoader that was used to create this AppContext. */ private final ClassLoader contextClassLoader; --- 222,232 ---- * incremented at the beginning of the constructor, and decremented * at the end of dispose(). getAppContext() checks to see if this * number is 1. If so, it returns the sole AppContext without * checking Thread.currentThread(). */ ! private static final AtomicInteger numAppContexts; /* * The context ClassLoader that was used to create this AppContext. */ private final ClassLoader contextClassLoader;
*** 241,251 **** * @param threadGroup The ThreadGroup for the new AppContext * @see sun.awt.SunToolkit * @since 1.2 */ AppContext(ThreadGroup threadGroup) { ! numAppContexts++; this.threadGroup = threadGroup; threadGroup2appContext.put(threadGroup, this); this.contextClassLoader = --- 243,253 ---- * @param threadGroup The ThreadGroup for the new AppContext * @see sun.awt.SunToolkit * @since 1.2 */ AppContext(ThreadGroup threadGroup) { ! numAppContexts.incrementAndGet(); this.threadGroup = threadGroup; threadGroup2appContext.put(threadGroup, this); this.contextClassLoader =
*** 276,286 **** * @return the AppContext for the caller. * @see java.lang.ThreadGroup * @since 1.2 */ public final static AppContext getAppContext() { ! if (numAppContexts == 1) // If there's only one system-wide, return mainAppContext; // return the main system AppContext. AppContext appContext = threadAppContext.get(); if (null == appContext) { --- 278,288 ---- * @return the AppContext for the caller. * @see java.lang.ThreadGroup * @since 1.2 */ public final static AppContext getAppContext() { ! if (numAppContexts.get() == 1) // If there's only one system-wide, return mainAppContext; // return the main system AppContext. AppContext appContext = threadAppContext.get(); if (null == appContext) {
*** 501,511 **** synchronized (table) { this.table.clear(); // Clear out the Hashtable to ease garbage collection } ! numAppContexts--; mostRecentKeyValue = null; } static final class PostShutdownEventRunnable implements Runnable { --- 503,513 ---- synchronized (table) { this.table.clear(); // Clear out the Hashtable to ease garbage collection } ! numAppContexts.decrementAndGet(); mostRecentKeyValue = null; } static final class PostShutdownEventRunnable implements Runnable {