Почему время вычислений в потоке main гораздо больше, чем в других?
Почему в приведенном коде время проведения аналогичных вычислений в разных потоках значительно отличаются?
public class qqq {
public static int result;
public static final int COUNT = 1_000_000_000;
public static void main(String[] args) throws InterruptedException {
Date start = new Date();
while (result < COUNT)
result++;
Date end = new Date();
System.out.println("main result = " + result + ". Calculated in " + (end.getTime() - start.getTime()) + " ms");
result = 0;
MyFirstThread mft = new MyFirstThread();
Thread t1 = new Thread(mft);
start = new Date();
t1.start();
t1.join();
end = new Date();
System.out.println("t1 result = " + result + ". Calculated in " + (end.getTime() - start.getTime()) + " ms");
}
public static class MyFirstThread implements Runnable {
public void run() {
int t = 0;
while (t < COUNT) {
t++;
}
result += t;
}
}
}