< prev index next >

src/java.base/share/classes/sun/net/www/http/KeepAliveCache.java

Print this page




  79      */
  80     public synchronized void put(final URL url, Object obj, HttpClient http) {
  81         boolean startThread = (keepAliveTimer == null);
  82         if (!startThread) {
  83             if (!keepAliveTimer.isAlive()) {
  84                 startThread = true;
  85             }
  86         }
  87         if (startThread) {
  88             clear();
  89             /* Unfortunately, we can't always believe the keep-alive timeout we got
  90              * back from the server.  If I'm connected through a Netscape proxy
  91              * to a server that sent me a keep-alive
  92              * time of 15 sec, the proxy unilaterally terminates my connection
  93              * The robustness to get around this is in HttpClient.parseHTTP()
  94              */
  95             final KeepAliveCache cache = this;
  96             java.security.AccessController.doPrivileged(
  97                 new java.security.PrivilegedAction<>() {
  98                 public Void run() {
  99                     keepAliveTimer = new InnocuousThread(cache, "Keep-Alive-Timer");
 100                     keepAliveTimer.setDaemon(true);
 101                     keepAliveTimer.setPriority(Thread.MAX_PRIORITY - 2);
 102                     // Set the context class loader to null in order to avoid
 103                     // keeping a strong reference to an application classloader.
 104                     keepAliveTimer.setContextClassLoader(null);
 105                     keepAliveTimer.start();
 106                     return null;
 107                 }
 108             });
 109         }
 110 
 111         KeepAliveKey key = new KeepAliveKey(url, obj);
 112         ClientVector v = super.get(key);
 113 
 114         if (v == null) {
 115             int keepAliveTimeout = http.getKeepAliveTimeout();
 116             v = new ClientVector(keepAliveTimeout > 0?
 117                                  keepAliveTimeout*1000 : LIFETIME);
 118             v.put(http);
 119             super.put(key, v);
 120         } else {
 121             v.put(http);
 122         }
 123     }
 124 




  79      */
  80     public synchronized void put(final URL url, Object obj, HttpClient http) {
  81         boolean startThread = (keepAliveTimer == null);
  82         if (!startThread) {
  83             if (!keepAliveTimer.isAlive()) {
  84                 startThread = true;
  85             }
  86         }
  87         if (startThread) {
  88             clear();
  89             /* Unfortunately, we can't always believe the keep-alive timeout we got
  90              * back from the server.  If I'm connected through a Netscape proxy
  91              * to a server that sent me a keep-alive
  92              * time of 15 sec, the proxy unilaterally terminates my connection
  93              * The robustness to get around this is in HttpClient.parseHTTP()
  94              */
  95             final KeepAliveCache cache = this;
  96             java.security.AccessController.doPrivileged(
  97                 new java.security.PrivilegedAction<>() {
  98                 public Void run() {
  99                     keepAliveTimer = new InnocuousThread(cache, "Keep-Alive-Timer", false);
 100                     keepAliveTimer.setDaemon(true);
 101                     keepAliveTimer.setPriority(Thread.MAX_PRIORITY - 2);



 102                     keepAliveTimer.start();
 103                     return null;
 104                 }
 105             });
 106         }
 107 
 108         KeepAliveKey key = new KeepAliveKey(url, obj);
 109         ClientVector v = super.get(key);
 110 
 111         if (v == null) {
 112             int keepAliveTimeout = http.getKeepAliveTimeout();
 113             v = new ClientVector(keepAliveTimeout > 0?
 114                                  keepAliveTimeout*1000 : LIFETIME);
 115             v.put(http);
 116             super.put(key, v);
 117         } else {
 118             v.put(http);
 119         }
 120     }
 121 


< prev index next >