How to shutdown com.sun.net.httpserver.HttpServer?

前端 未结 4 1781
暗喜
暗喜 2021-02-10 12:34

The Http Server embedded in JDK 6 is a big help developing web services, but I\'ve got situation where I published an Endpoint and then the code crashed and left the server runn

4条回答
  •  一整个雨季
    2021-02-10 13:19

    I use the below code to start it

        this.httpServer = HttpServer.create(addr, 0);
        HttpContext context = this.httpServer.createContext("/", new DocumentProcessHandler());
        this.httpThreadPool = Executors.newFixedThreadPool(this.noOfThreads);
        this.httpServer.setExecutor(this.httpThreadPool);
        this.httpServer.start();
    

    and below code to stop it

            this.httpServer.stop(1);
            this.httpThreadPool.shutdownNow();
    

提交回复
热议问题