I have the following code:
class Counter2 extends Thread {
public Counter2(String s) {
super(s);
};
public void run() {
Thread thread = currentThread();
for (long count = 0; count <= 1; ++count)
System.out.println(thread + "COUNT:" + count);
}
}
public class ThreadTest {
public static void main(String[] args) {
Thread secondThread = new Counter2("second");
Thread thirdThread = new Counter2("third");
thirdThread.setPriority(8);
secondThread.start();
thirdThread.start();
}
}
When running the program, I expect to get the following output:
Thread[third,8,main]COUNT:0
Thread[third,8,main]COUNT:1
Thread[second,5,main]COUNT:1
Thread[second,5,main]COUNT:0
Instead I just get different results in different order every time i execute the program and it seems like java is executing the method on both threads at the same time, but i thought it would prioritize the method with the higher priority?