I am using jetty 9 in embedded mode and even though i have given a threadpool
of 500 the server still just handle one request at a time.
What am i missing ?
JAVA CODE:
// here i expect all thread name log to print instantaneously but they print one by one
public class Main {
public static void main(String[] arg) throws Exception {
ExecutorThreadPool executorThreadPool = new ExecutorThreadPool(Executors.newFixedThreadPool(500));
final Server server = new Server(executorThreadPool);
final ServerConnector connector0 = new ServerConnector(server);
connector0.addBean(executorThreadPool);
connector0.setPort(8080);
server.setHandler(new HelloHandler());
server.setConnectors(new Connector[] {connector0});
server.setDumpAfterStart(true);
server.start();
server.join();
}
}
class HelloHandler extends AbstractHandler
{
public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException
{
try {
System.out.println("Thread Name+" + Thread.currentThread().getName());
Thread.sleep(3000l);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("<h1>Hello World</h1>");
}
}
POM.XML
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.2.6.v20141205</version>
</dependency>
</dependencies>
</project>
JAVASCRIPT script i fired from my browser to test"
function httpGet(theUrl)
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, true );
xmlHttp.send( null );
return xmlHttp.responseText;
}
for(i=0;i<20;i++) {console.log(i);httpGet("http://localhost:8080");}