我使用了java 自带的com.sun.net.httpserver,使用多线程接收消息,但是当我在一个线程中加入死循环,客户端第二个请求就接收不到,求大神指点
HttpServerProvider provider = HttpServerProvider.provider();
HttpServer httpserver =provider.createHttpServer(new InetSocketAddress(port), revCount);//监听端口9006,能同时接 受100个请求
httpserver.createContext(context, new HandlerProto());
// httpserver.setExecutor(null); //使用单线程
httpserver.setExecutor(Executors.newCachedThreadPool());
httpserver.start();
- public void handle(HttpExchange httpExchange) throws IOException {
- // TODO Auto-generated method stub
- String method = httpExchange.getRequestMethod();
- if(method.equalsIgnoreCase("GET")){
- System.out.println("===>"+Thread.currentThread().getId());
- System.out.println("===>"+httpExchange.getRequestURI());
-
- boolean ffff = true;
- while(ffff){
-
- }
- byte[] resout = "123".getBytes();
- try {
- httpExchange.sendResponseHeaders(200, resout.length); //设置响应头属性及响应信息的长度
- OutputStream out = httpExchange.getResponseBody(); //获得输出流
-
- out.write(resout);
- out.flush();
- out.close();
- httpExchange.close();
-
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- }