--- old/src/share/classes/sun/awt/AppContext.java 2011-08-19 10:22:55.990366402 +0200 +++ new/src/share/classes/sun/awt/AppContext.java 2011-08-19 10:22:55.715369839 +0200 @@ -46,6 +46,7 @@ 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 @@ -195,6 +196,8 @@ } static { + numAppContexts = new AtomicInteger(0); + // 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. @@ -209,7 +212,6 @@ parentThreadGroup = currentThreadGroup.getParent(); } mainAppContext = new AppContext(currentThreadGroup); - numAppContexts = 1; return mainAppContext; } }); @@ -222,7 +224,7 @@ * number is 1. If so, it returns the sole AppContext without * checking Thread.currentThread(). */ - private static volatile int numAppContexts; + private static final AtomicInteger numAppContexts; /* * The context ClassLoader that was used to create this AppContext. @@ -243,7 +245,7 @@ * @since 1.2 */ AppContext(ThreadGroup threadGroup) { - numAppContexts++; + numAppContexts.incrementAndGet(); this.threadGroup = threadGroup; threadGroup2appContext.put(threadGroup, this); @@ -278,7 +280,7 @@ * @since 1.2 */ public final static AppContext getAppContext() { - if (numAppContexts == 1) // If there's only one system-wide, + if (numAppContexts.get() == 1) // If there's only one system-wide, return mainAppContext; // return the main system AppContext. AppContext appContext = threadAppContext.get(); @@ -503,7 +505,7 @@ this.table.clear(); // Clear out the Hashtable to ease garbage collection } - numAppContexts--; + numAppContexts.decrementAndGet(); mostRecentKeyValue = null; }