From 1edefcae08fe7c8df6a177e5dbbc8ab8f8194187 Mon Sep 17 00:00:00 2001 From: wu <731351411@qq.com> Date: 星期二, 31 十二月 2024 08:21:24 +0800 Subject: [PATCH] 更改启动项目设置 --- nglib/src/builder/ThreadHttpServer.java | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-) diff --git a/nglib/src/builder/ThreadHttpServer.java b/nglib/src/builder/ThreadHttpServer.java new file mode 100644 index 0000000..49be5e1 --- /dev/null +++ b/nglib/src/builder/ThreadHttpServer.java @@ -0,0 +1,30 @@ +package builder; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import com.sun.net.httpserver.*; + +public class ThreadHttpServer { + //启动端口8080 + private static final int port=8880; + private static final String Httpcontext="/demo"; + private static final int nThreads=8; + public static void mains() { + HttpServer httpServer; + try { + httpServer=HttpServer.create(new InetSocketAddress(port),0); + httpServer.createContext(Httpcontext,new HttpHandlerDemo() ); +// 设置并发数 + ExecutorService executor=Executors.newFixedThreadPool(nThreads); + httpServer.setExecutor(executor); + httpServer.start(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} -- Gitblit v1.8.0