jdk/src/share/classes/sun/awt/AppContext.java
changeset 19809 dc0480c1b36c
parent 19174 175494bb464e
child 20792 8d5c16e4f64c
child 21242 dd191df75e13
equal deleted inserted replaced
19808:39cb79123ab2 19809:dc0480c1b36c
   836                 return (ac == null) ? true : ac.isDisposed();
   836                 return (ac == null) ? true : ac.isDisposed();
   837             }
   837             }
   838             public boolean isMainAppContext() {
   838             public boolean isMainAppContext() {
   839                 return (numAppContexts.get() == 1 && mainAppContext != null);
   839                 return (numAppContexts.get() == 1 && mainAppContext != null);
   840             }
   840             }
   841             public Object getContext() {
   841 
   842                 return getAppContext();
   842             /**
   843             }
   843              * Returns the AppContext used for applet logging isolation, or null if
   844             public Object getExecutionContext() {
   844              * the default global context can be used.
   845                 return getExecutionAppContext();
   845              * If there's no applet, or if the caller is a stand alone application,
   846             }
   846              * or running in the main app context, returns null.
   847             public Object get(Object context, Object key) {
   847              * Otherwise, returns the AppContext of the calling applet.
   848                 return ((AppContext)context).get(key);
   848              * @return null if the global default context can be used,
   849             }
   849              *         an AppContext otherwise.
   850             public void put(Object context, Object key, Object value) {
   850              **/
   851                 ((AppContext)context).put(key, value);
   851             public Object getAppletContext() {
   852             }
   852                 // There's no AppContext: return null.
   853             public void remove(Object context, Object key) {
   853                 // No need to call getAppContext() if numAppContext == 0:
   854                 ((AppContext)context).remove(key);
   854                 // it means that no AppContext has been created yet, and
   855             }
   855                 // we don't want to trigger the creation of a main app
       
   856                 // context since we don't need it.
       
   857                 if (numAppContexts.get() == 0) return null;
       
   858 
       
   859                 // Get the context from the security manager
       
   860                 AppContext ecx = getExecutionAppContext();
       
   861 
       
   862                 // Not sure we really need to re-check numAppContexts here.
       
   863                 // If all applets have gone away then we could have a
       
   864                 // numAppContexts coming back to 0. So we recheck
       
   865                 // it here because we don't want to trigger the
       
   866                 // creation of a main AppContext in that case.
       
   867                 // This is probably not 100% MT-safe but should reduce
       
   868                 // the window of opportunity in which that issue could
       
   869                 // happen.
       
   870                 if (numAppContexts.get() > 0) {
       
   871                    // Defaults to thread group caching.
       
   872                    // This is probably not required as we only really need
       
   873                    // isolation in a deployed applet environment, in which
       
   874                    // case ecx will not be null when we reach here
       
   875                    // However it helps emulate the deployed environment,
       
   876                    // in tests for instance.
       
   877                    ecx = ecx != null ? ecx : getAppContext();
       
   878                 }
       
   879 
       
   880                 // getAppletContext() may be called when initializing the main
       
   881                 // app context - in which case mainAppContext will still be
       
   882                 // null. To work around this issue we simply use
       
   883                 // AppContext.threadGroup.getParent() == null instead, since
       
   884                 // mainAppContext is the only AppContext which should have
       
   885                 // the root TG as its thread group.
       
   886                 // See: JDK-8023258
       
   887                 final boolean isMainAppContext = ecx == null
       
   888                     || mainAppContext == ecx
       
   889                     || mainAppContext == null && ecx.threadGroup.getParent() == null;
       
   890 
       
   891                 return isMainAppContext ? null : ecx;
       
   892             }
       
   893 
   856         });
   894         });
   857     }
   895     }
   858 }
   896 }
   859 
   897 
   860 final class MostRecentKeyValue {
   898 final class MostRecentKeyValue {