无法使用 Jetty 服务器线程池最大大小限制并发请求,为什么?
我创建了一个带有线程池的 Jetty 服务器来限制对服务器的并发请求数量。但我指定的总请求大小始终比我指定的大小小 5。依赖关系:<dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-server</artifactId> <version>9.4.6.v20170531</version></dependency>服务器代码:public void httpServer(int port, Handler handler, String name) { QueuedThreadPool threadPool = new QueuedThreadPool(10); Server server = new Server(threadPool); server.setHandler(handler); HttpConfiguration http = new HttpConfiguration(); ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory(http)); serverConnector.setPort(port); server.setConnectors(new Connector[]{serverConnector}); try { log.info(name + " Listener Started on port: " + port); server.start(); server.join(); } catch (Exception e) { log.error("Unable to start Server... Exiting"); log.error(e, e); System.exit(1); }}处理程序:public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { try { BufferedReader bufferedReader = request.getReader(); String s; StringBuilder sb = new StringBuilder(); PrintWriter writer = response.getWriter(); while ((s = bufferedReader.readLine()) != null) { sb.append(s); } System.out.println("Got Request"); Thread.sleep(2000); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); } catch (Exception e) { e.printStackTrace(); }}在上面的代码中,指定的 ThreadPool 大小为 10。但同时我只能创建 5。我尝试将大小更改为 20,但在这种情况下,我可以发出的并发请求始终少 5,即 15。知道在哪里吗?这 5 个线程正在被使用吗?
查看完整描述