8014254: Selector in HttpServer introduces a 1000 ms delay when using KeepAlive
authorkhazra
Mon, 13 May 2013 13:48:58 -0700
changeset 17463 9392f1567896
parent 17462 c1bfafc15e02
child 17464 268d3ce75045
child 17480 e2177bd019a2
8014254: Selector in HttpServer introduces a 1000 ms delay when using KeepAlive Summary: Rearrange event-handling code to remove bottle-neck. Also reviewed by mhall@mhcomputing.net. Reviewed-by: chegar, alanb
jdk/src/share/classes/sun/net/httpserver/ServerImpl.java
--- a/jdk/src/share/classes/sun/net/httpserver/ServerImpl.java	Mon May 13 13:15:20 2013 -0700
+++ b/jdk/src/share/classes/sun/net/httpserver/ServerImpl.java	Mon May 13 13:48:58 2013 -0700
@@ -321,15 +321,7 @@
         public void run() {
             while (!finished) {
                 try {
-                    ListIterator<HttpConnection> li =
-                        connsToRegister.listIterator();
-                    for (HttpConnection c : connsToRegister) {
-                        reRegister(c);
-                    }
-                    connsToRegister.clear();
-
                     List<Event> list = null;
-                    selector.select(1000);
                     synchronized (lolock) {
                         if (events.size() > 0) {
                             list = events;
@@ -343,8 +335,14 @@
                         }
                     }
 
+                    for (HttpConnection c : connsToRegister) {
+                        reRegister(c);
+                    }
+                    connsToRegister.clear();
+
+                    selector.select(1000);
+
                     /* process the selected list now  */
-
                     Set<SelectionKey> selected = selector.selectedKeys();
                     Iterator<SelectionKey> iter = selected.iterator();
                     while (iter.hasNext()) {