【发布时间】:2011-07-24 08:49:24
【问题描述】:
我正在线程上打个招呼,我创建了一个使用 run() 调用的简单线程(它只是一个普通的方法调用)和一个使用 start() 调用产生另一个线程的重复线程但是,要处理start() 调用所花费的时间比run() 调用所花费的时间要多,这不是线程调用,为什么会这样?
开始通话时间:00:00:08:300
long time = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
Thread thread = new Thread(new Car());
thread.setName(Integer.toString(i));
thread.start();
}
long completedIn = System.currentTimeMillis() - time;
System.out.println(DurationFormatUtils.formatDuration(completedIn,
"HH:mm:ss:SS"));
运行调用时间:00:00:01:366
long time = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
Thread thread = new Thread(new Car());
thread.setName(Integer.toString(i));
thread.run();
}
long completedIn = System.currentTimeMillis() - time;
System.out.println(DurationFormatUtils.formatDuration(completedIn,
"HH:mm:ss:SS"));
【问题讨论】:
标签: java multithreading