📄 gctest.java
字号:
package net.betterjava.sample.xml.bind.test;
import java.io.FileNotFoundException;
import java.io.IOException;
public class GCTest {
private static void description() {
System.out.println("usage: java -jar GCTest.jar -round -thread -root");
System.out.println("-round\t round of test, an integer greater than zero");
System.out.println("-thread\t number of thread, an integer greater than zero");
System.out.println("-root\t the directory of input data file ");
}
private static void warming(String root)
throws IOException, FileNotFoundException, InterruptedException {
int thread = 5;
int round = 50;
ServerSimulation[] server = new ServerSimulation[thread];
Semaphore smp = new Semaphore(thread, round);
for (int i = 0; i < thread; i++) {
server[i] = new ServerSimulation(smp, root + "template.xsd");
}
for (int i = 0; i < thread; i++) {
server[i].start();
}
for (int i = 0; i < thread; i++) {
server[i].join();
}
System.gc();
long time = System.currentTimeMillis();
int temp = 0;
for (int i = 0; i < 1000; i++) {
temp = 0;
for (int j = 0; j < 10000; j++) {
temp++;
}
}
System.out.println("warming time: " + (System.currentTimeMillis() - time));
}
public static void main(String[] args) {
if (args.length != 3) {
description();
return;
}
int round;
int thread;
String root = ".\\";
try {
round = Integer.parseInt(args[0]);
thread = Integer.parseInt(args[1]);
root = args[2];
} catch (NumberFormatException e) {
description();
return;
}
if (round <= 0 || thread <= 0) {
description();
return;
}
try {
warming(root);
ServerSimulation[] server = new ServerSimulation[thread];
Semaphore smp = new Semaphore(thread, round);
for (int i = 0; i < thread; i++) {
server[i] = new ServerSimulation(smp, root + "template.xsd");
}
for (int i = 0; i < thread; i++) {
server[i].start();
}
for (int i = 0; i < thread; i++) {
server[i].join();
}
System.out.println(round + " is " + smp.getElapseTime());
} catch (FileNotFoundException e) {
e.printStackTrace(System.out);
} catch (IOException e) {
e.printStackTrace(System.out);
} catch (InterruptedException e) {
e.printStackTrace(System.out);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -