Embedded Jetty 9一次处理一个请求

时间:2015-01-09 09:11:31

标签: java javascript embedded-jetty jetty-9

我在嵌入模式下使用jetty 9,即使我已经给出了threadpool 500,服务器仍然只能处理一个请求。

我缺少什么?

JAVA CODE:
    //这里我希望所有 线程名称 日志即时打印,但它们会逐个打印

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脚本以测试&#34;

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");}

0 个答案:

没有答案