-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
7u17
FULL PRODUCT VERSION :
java version " 1.7.0_17 "
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
When a resource is published with the internal HttpServer, and if this resource is accessed, then in Java7 there is a delay of approx 1000ms. In Java6 the access to the data over a stream used 5ms approx only.
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program both with Java6 and with Java7.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If the server is running with Java6, then a Java6 client prints the following result:
% java EchoClient
<
1362515635677
<
1362515635682
<
1362515635687
<
1362515635691
i.e. every approx 5ms a result is printed
ACTUAL -
If the server is running with Java7, then a Java7 client prints the following result:
% java EchoClient
<
1362517297845
<
1362517298844
<
1362517299845
<
1362517300845
i.e. every approx 1000ms a result is printed.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.Date;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public class EchoServer {
public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(80), 0);
server.createContext( " /echo " , new EchoHandler());
server.start();
}
static class EchoHandler implements HttpHandler {
public void handle(HttpExchange httpExchange) throws IOException {
httpExchange.getResponseHeaders().add( " Content-type " , " text/html " );
String response = " <b> " + new Date() + " </b> for " + httpExchange.getRequestURI();
httpExchange.sendResponseHeaders(200, response.length());
OutputStream os = httpExchange.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class EchoClient {
public static void main(String[] args) throws Exception{
while(true) {
URL url = new URL( " http://localhost:80/echo " );
BufferedReader rd = new BufferedReader(new InputStreamReader(url.openStream()));
int res = rd.read();
System.out.println((char)res);
System.out.println(System.currentTimeMillis());
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I have found no workaround with HttpServer.
java version " 1.7.0_17 "
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
When a resource is published with the internal HttpServer, and if this resource is accessed, then in Java7 there is a delay of approx 1000ms. In Java6 the access to the data over a stream used 5ms approx only.
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program both with Java6 and with Java7.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If the server is running with Java6, then a Java6 client prints the following result:
% java EchoClient
<
1362515635677
<
1362515635682
<
1362515635687
<
1362515635691
i.e. every approx 5ms a result is printed
ACTUAL -
If the server is running with Java7, then a Java7 client prints the following result:
% java EchoClient
<
1362517297845
<
1362517298844
<
1362517299845
<
1362517300845
i.e. every approx 1000ms a result is printed.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.Date;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public class EchoServer {
public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(80), 0);
server.createContext( " /echo " , new EchoHandler());
server.start();
}
static class EchoHandler implements HttpHandler {
public void handle(HttpExchange httpExchange) throws IOException {
httpExchange.getResponseHeaders().add( " Content-type " , " text/html " );
String response = " <b> " + new Date() + " </b> for " + httpExchange.getRequestURI();
httpExchange.sendResponseHeaders(200, response.length());
OutputStream os = httpExchange.getResponseBody();
os.write(response.getBytes());
os.close();
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class EchoClient {
public static void main(String[] args) throws Exception{
while(true) {
URL url = new URL( " http://localhost:80/echo " );
BufferedReader rd = new BufferedReader(new InputStreamReader(url.openStream()));
int res = rd.read();
System.out.println((char)res);
System.out.println(System.currentTimeMillis());
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I have found no workaround with HttpServer.
- duplicates
-
JDK-8014254 Selector in HttpServer introduces a 1000 ms delay when using KeepAlive
- Resolved