public class Workkk {
public static void main(String[] args) {
final HomeWorkee h = new HomeWorkee();
new Thread() {
public void run() {
for (int i = 0; i < 3; i++)
try {
h.haha();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
new Thread() {
public void run() {
for (int i = 0; i < 3; i++)
try {
h.hah();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
new Thread() {
public void run() {
for (int i = 0; i < 3; i++)
try {
h.ha();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
}
class HomeWorkee {
private int x = 1;
private int flag = 3; //标记为3,只能最先执行线程1