// class Helper remains unchanged
final class RequestHandler {
private final Helper h = new Helper();
private staticfinal ServerSocket server;
private staticfinal ExecutorService exec;
private RequestHandler(int port, int poolSize) throws IOException {
server = new ServerSocket(port);
exec = Executors.newFixedThreadPool(poolSize);
}
public static RequestHandler getInstance(int port, int poolSize) throws IOException {
return new RequestHandler(port, poolSize);
}
public void handleRequest() {
exec.submit(new Runnable() {
public void run() {
try {
h.handle(server.accept());
} catch (IOException e) {
// Forward to handler
}
}
});
}
}
|