用java编程:创建三个线程,分别显示各自的开始运行时间及总运行时间

} public void run() { long startTime = System.currentMillis();System.out.println(name + " start at : " + startTime);Thread.sleep(1000);System.out.println(name + " totoal cost : " + (System.currentMillis() - startTime));} } public class Test { public static void main...
用java编程:创建三个线程,分别显示各自的开始运行时间及总运行时间
public class AThread extends Thread {
private String name;

public AThread(String name) {
this.name = name;
}
public void run() {
long startTime = System.currentMillis();
System.out.println(name + " start at : " + startTime);
Thread.sleep(1000);
System.out.println(name + " totoal cost : " + (System.currentMillis() - startTime));
}
}

public class Test {
public static void main(String[] args) {
for (int i = 0; i < 3; i++) {
AThread t = new AThread("thread " + i);
t.start();
}
}
}2009-04-24
mengvlog 阅读 51 次 更新于 2025-12-19 01:43:10 我来答关注问题0
檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部