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
--- 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()) {