Test web page multiple thread support
package test2;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.InputStreamReader;
import java.net.URL;
public class ThreadSafetyTest implements Runnable {
public static void main(String args[]) {
long t0 = System.currentTimeMillis();
Runnable run = new ThreadSafetyTest();
/** 20 consecutice accesses used ms */
// for (int i = 0; i < 20; i++) {
// run.run();
//}
/** 20 concurrent accesses used ms (the last thread time */
for (int i = 0; i < 10; i++) {
Thread thread = new Thread(run);
// thread.setDaemon(true); // so program can exit
thread.start();
}
long t1 = System.currentTimeMillis();
System.out.println("Program time used = " + (t1 - t0) + " ms.");
}
public void run() {
long t0 = System.currentTimeMillis();
DataInputStream dis;
try {
String urlString = "http://localhost:8011/mrcjava/servlet/MRCJAVALIB.I00116a";
//String urlString = "http://www.ibm.com";
URL url = new URL(urlString);
dis = new DataInputStream(url.openConnection().getInputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(dis));
String total = "";
String line = "";
while ((line = in.readLine()) != null) {
total += line;
}
in.close();
long t1 = System.currentTimeMillis();
System.out.println("Response size = " + total.length()
+ ", time used = " + (t1 - t0) + " ms.");
} catch (Exception e) {
System.out.println(e);
}
}
}
Lets run it against a server on a windows XP box.
When accessing a page that does not support multiple threading (I00116s) the output is:
Response size = 16602, time used = 531 ms.
Response size = 16602, time used = 969 ms.
Response size = 16602, time used = 1391 ms.
Response size = 16602, time used = 1766 ms.
Response size = 16602, time used = 2266 ms.
Response size = 16602, time used = 2672 ms.
Response size = 16602, time used = 3078 ms.
Response size = 16602, time used = 3453 ms.
Response size = 16602, time used = 3844 ms.
Response size = 16602, time used = 4234 ms.
You can see the longest response time is 4,234 mini seconds.
Response size = 17399, time used = 281 ms.
Response size = 17399, time used = 359 ms.
Response size = 17399, time used = 672 ms.
Response size = 17399, time used = 719 ms.
Response size = 17399, time used = 875 ms.
Response size = 17399, time used = 922 ms.
Response size = 17399, time used = 953 ms.
Response size = 17399, time used = 953 ms.
Response size = 17399, time used = 969 ms.
Response size = 17399, time used = 969 ms.
You can see the longest response time is 969 mini seconds.
0 Comments:
Post a Comment
<< Home