concurrencypuzzlers/src/chapter6/CachedThreadPool.java
2019-09-20 13:34:33 +02:00

23 lines
656 B
Java

package chapter6;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class CachedThreadPool {
private static final Executor threadpool = Executors.newCachedThreadPool();
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = new ServerSocket(80);
for (; ; ) {
Socket clientSocket = serverSocket.accept();
threadpool.execute(() -> handleRequest(clientSocket));
}
}
private static void handleRequest(Socket clientSocket) {
//
}
}