All pastes #675098 Raw Edit

Someone

public java v1 · immutable
#675098 ·published 2007-08-29 20:34 UTC
rendered paste body
package stresstest;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.Socket;/** * * @author gharding */public class Main {        private static final int THREADS = 1000;        public static void main(String[] args) {        for (int i = 0; i < THREADS; i++) {            new Thread(new Runnable() {                public void run() {                    Socket socket = null;                    PrintWriter out = null;                    BufferedReader in = null;                    try {                        socket = new Socket("localhost", 8080);                        out = new PrintWriter(socket.getOutputStream(), true);                        in = new BufferedReader(new InputStreamReader(socket.getInputStream()));                                                                                            } catch (Exception e){System.out.println(e.getMessage());}                    out.print("GET /ratesComet HTTP/1.1\nHost: localhost\n\n");                    out.flush();                                        try {                        String strIn;                        while ((strIn = in.readLine()) != null) {                            //System.out.println(strIn);                        }                     } catch (IOException ioe) { System.out.println(ioe.getMessage()); }                }            }).start();                        if (i % 50 == 0) System.out.println("Threads started: "+i);                    }        while (true) {            System.out.println("Active threads: "+Thread.activeCount());            if (Thread.activeCount() > 1) {                try {                    Thread.sleep(5000);                } catch (Exception e) {}            }        }    }}