public class Main {
public static void main(String[] args) {
/*
* A[] a = new A[2]; for (int i = 0; i < A.length; i++) a[i] = new A(i);
* a[0].setPriority(2); a[1].setPriority(3); a[0].start(); a[1].start();
*/
TestThread[] runners = new TestThread[2];
for (int i = 0; i < 2; i++) {
runners[i] = new TestThread(i);
}
runners[0].setPriority(2);
runners[1].setPriority(3);
for (int i = 0; i < 2; i++) {
runners[i].start();
}
}
}
class TestThread extends Thread {
private int tick = 1, num;
public TestThread(int num) {
this.num = num;
}
public void run() {
while (tick < 40000) {
tick++;
if (tick % 5000 == 0) {
System.out.println("Thread#" + num + ",tick=" + tick);
yield();
}
}
}
}