/*多线程之间各自的运行时间
* 在线程开始是设置一个时间,线程结束后取一时间,然后得到两时间差就是线程执行时间
* */
public class Test implements Runnable {
public static void main(String[] args) {
Test6 t6 = new Test6();
Thread t = new Thread(t6);
Test6 t61 = new Test6();
Thread t1 = new Thread(t61);
t.start();
t1.start();
for (int i = 0; i < 20; i++) {
System.out.println("main" + i);
}
}
public void run() {
long beginTime = System.currentTimeMillis();
for (int i = 0; i < 20; i++) {
System.out.println("run:" + i);
}
long endTime = System.currentTimeMillis();
System.out.println("cost TIMEMILLIS: " + (endTime - beginTime));
}
}