Mercurial Hosting > luan
diff src/luan/webserver/Server.java @ 1187:83c8a5a47f70
fixes for luanhost
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 22 Feb 2018 18:38:45 -0700 |
parents | 79b1e9ffd0c0 |
children | 8b61c8c4e07a |
line wrap: on
line diff
--- a/src/luan/webserver/Server.java Wed Feb 21 21:50:20 2018 -0700 +++ b/src/luan/webserver/Server.java Thu Feb 22 18:38:45 2018 -0700 @@ -5,7 +5,7 @@ import java.net.ServerSocket; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.concurrent.ExecutorService; +import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.slf4j.Logger; @@ -17,7 +17,7 @@ public final int port; public final Handler handler; - private static final ExecutorService exec = Executors.newCachedThreadPool(); + public static final ThreadPoolExecutor threadPool = (ThreadPoolExecutor)Executors.newCachedThreadPool(); public Server(int port,Handler handler) { this.port = port; @@ -30,11 +30,11 @@ public synchronized void start() throws IOException { final ServerSocket ss = newServerSocket(); - exec.execute(new Runnable(){public void run() { + threadPool.execute(new Runnable(){public void run() { try { - while(!exec.isShutdown()) { + while(!threadPool.isShutdown()) { final Socket socket = ss.accept(); - exec.execute(new Runnable(){public void run() { + threadPool.execute(new Runnable(){public void run() { Connection.handle(Server.this,socket); }}); } @@ -47,8 +47,8 @@ public synchronized boolean stop(long timeoutSeconds) { try { - exec.shutdownNow(); - boolean stopped = exec.awaitTermination(timeoutSeconds,TimeUnit.SECONDS); + threadPool.shutdownNow(); + boolean stopped = threadPool.awaitTermination(timeoutSeconds,TimeUnit.SECONDS); if(stopped) logger.info("stopped server on port "+port); else