1 // Use with "nc localhost 8080 < /dev/null"
2 // Idle threads are parked by the jsr166 framework and caused lots of CPU usage
3 // before the addition of park/unpark to CACAO.
6 import java.io.IOException;
7 import java.io.PrintWriter;
8 import java.util.concurrent.Executor;
9 import java.util.concurrent.Executors;
10 import java.net.InetSocketAddress;
12 public class threadpooltest {
13 private static final int NTHREADS = 3;
14 private static final Executor exec = Executors.newFixedThreadPool(NTHREADS);
16 private static void handleRequest(Socket s) {
19 if (Thread.currentThread().isInterrupted())
20 ss += " (wasinterrupted)";
21 ss += " " + Thread.currentThread().toString();
22 PrintWriter pw = new PrintWriter(s.getOutputStream());
23 //Thread.currentThread().interrupt();
27 pw.println("closing");
30 } catch (InterruptedException e) {
32 } catch (IOException e) {
37 public static void main(String[] args) throws IOException {
38 ServerSocket socket = new ServerSocket();
39 socket.setReuseAddress(true);
40 socket.bind(new InetSocketAddress(8080));
42 final Socket connection = socket.accept();
43 Runnable task = new Runnable() {
45 handleRequest(connection);