jdk/src/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java
changeset 4916 de44744708a2
parent 4157 558590fb3b49
child 5199 98b1778f0fd1
equal deleted inserted replaced
4915:fe435c741ec8 4916:de44744708a2
   109      * Authenticator for a particular realm is single threaded.
   109      * Authenticator for a particular realm is single threaded.
   110      * ie. if multiple threads need to get credentials from the user
   110      * ie. if multiple threads need to get credentials from the user
   111      * at the same time, then all but the first will block until
   111      * at the same time, then all but the first will block until
   112      * the first completes its authentication.
   112      * the first completes its authentication.
   113      */
   113      */
   114     static private HashMap requests = new HashMap ();
   114     static private HashMap<String,Thread> requests = new HashMap<>();
   115 
   115 
   116     /* check if a request for this destination is in progress
   116     /* check if a request for this destination is in progress
   117      * return false immediately if not. Otherwise block until
   117      * return false immediately if not. Otherwise block until
   118      * request is finished and return true
   118      * request is finished and return true
   119      */
   119      */
   123             return false;
   123             return false;
   124         }
   124         }
   125         synchronized (requests) {
   125         synchronized (requests) {
   126             Thread t, c;
   126             Thread t, c;
   127             c = Thread.currentThread();
   127             c = Thread.currentThread();
   128             if ((t=(Thread)requests.get(key))==null) {
   128             if ((t = requests.get(key)) == null) {
   129                 requests.put (key, c);
   129                 requests.put (key, c);
   130                 return false;
   130                 return false;
   131             }
   131             }
   132             if (t == c) {
   132             if (t == c) {
   133                 return false;
   133                 return false;
   145     /* signal completion of an authentication (whether it succeeded or not)
   145     /* signal completion of an authentication (whether it succeeded or not)
   146      * so that other threads can continue.
   146      * so that other threads can continue.
   147      */
   147      */
   148     static private void requestCompleted (String key) {
   148     static private void requestCompleted (String key) {
   149         synchronized (requests) {
   149         synchronized (requests) {
   150             boolean waspresent = requests.remove (key) != null;
   150             Thread thread = requests.get(key);
   151             assert waspresent;
   151             if (thread != null && thread == Thread.currentThread()) {
       
   152                 boolean waspresent = requests.remove(key) != null;
       
   153                 assert waspresent;
       
   154             }
   152             requests.notifyAll();
   155             requests.notifyAll();
   153         }
   156         }
   154     }
   157     }
   155 
   158 
   156     //public String toString () {
   159     //public String toString () {