I don't understand the output of this code:
package examplepriorities;
class Counter extends Thread {
public Counter(String name) {
super(name);
}
@Override
public void run() {
int count = 0;
while (count <= 1000) {
System.out.println(this.getName() + ": " + count++);
}
}
}
public class ExamplePriorities {
public static void main(String[] args) {
Counter thread1 = new Counter("thread 1");
thread1.setPriority(10);
Counter thread2 = new Counter("thread 2");
thread2.setPriority(1);
thread1.start();
thread2.start();
}
}
In the output you can see messages printed from the thread 1 from 0 to 1000 and, when these thread finish its work, the second thread start printing messages. I know that the first thread has higher priority level but as there are (i suppose) free cores in the processor, why both threads don't make their job at the same time?