我需要计算运行我编写的应用程序的每个线程需要多长时间,并且我已经完成并得到了结果,但实际上并没有任何好的方法来验证我是否做对了。我以前从来没有做过这样的事情。如果有人可以给我一个快速校对,那将非常有帮助。
这是创建线程的代码:
for (int i = 0; i < ROWS; i++) {
threads[threadCount] = new Thread(new TextDistanceThread("Macbeth.txt", "Othello.txt", i, 0));
threads[threadCount++].start();
threads[threadCount] = new Thread(new TextDistanceThread("Macbeth.txt", "HuckFinn.txt", i, 1));
threads[threadCount++].start();
threads[threadCount] = new Thread(new TextDistanceThread("Macbeth.txt", "TomSawyer.txt", i, 2));
threads[threadCount++].start();
threads[threadCount] = new Thread(new TextDistanceThread("Othello.txt", "HuckFinn.txt", i, 3));
threads[threadCount++].start();
threads[threadCount] = new Thread(new TextDistanceThread("Othello.txt", "TomSawyer.txt", i, 4));
threads[threadCount++].start();
threads[threadCount] = new Thread(new TextDistanceThread("TomSawyer.txt", "HuckFinn.txt", i, 5));
threads[threadCount++].start();
}
以及线程本身的代码:
public void run() {
long start = ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime();
//DO SOME STUFF
long end = ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime();
Driver.timeResults[0][row][col] = end - start;
Driver.results[row][col] = difference;
}