-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTestServlet.java
54 lines (44 loc) · 1.21 KB
/
TestServlet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class TestServlet {
public static void main(String [] args) throws InterruptedException {
TestRunner testrunner1 = new TestRunner();
Thread th1 = new Thread(testrunner1);
th1.start();
TestRunner testrunner2 = new TestRunner();
Thread th2 = new Thread(testrunner2);
th2.start();
th1.join();
th2.join();
}
}
class TestRunner implements Runnable {
@Override
public void run() {
String host = "localhost";
String resource = "/test-thread-servlet/threadServlet";
int portToUse = 8080;
int numOfRequests = 1000;
Socket client;
try {
for (int i=0; i<numOfRequests; i++) {
client = new Socket(host, portToUse);
OutputStream out = client.getOutputStream();
PrintWriter pout = new PrintWriter(out);
pout.write("GET " + resource + " " + "HTTP/1.1\n");
pout.write("Host: " + host + "\n");
pout.write("User-Agent: TestRunner\n");
pout.write("\n");
pout.flush();
out.close();
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}