package DieLock;
public class Teacher implements Runnable {
public static final Object obj1=new Object();
public static final Object obj2=new Object();
boolean flag;
Teacher(boolean flag) {
this.flag = flag;
}
@Override
public void run() {
while (true){
if(flag){
synchronized (obj1) {
System.out.println("obj1ture");
synchronized (obj2) {
System.out.println("obj1fase");
}
}}
else
synchronized (obj2) {
System.out.println("obj2ture");
synchronized (obj1) {
System.out.println("obj2fase");
}
}
}}
}
|
|