public class DeadLockEx {
private String str1 = "SPRING";
private String str2 = "HIBERNATE";
public static void main(String[] args) {
DeadLockEx app = new DeadLockEx();
app.t1.start();
app.t2.start();
}
Thread t1 = new Thread("Thead 1") {
public void run() {
while (true) {
synchronized (str1) {
synchronized (str2) {
System.out.println(str1 + str2);
}
}
}
}
};
Thread t2 = new Thread("Thead 2") {
public void run() {
while (true) {
synchronized (str2) {
synchronized (str1) {
System.out.println(str2 + str1);
}
}
}
}
};
}
No comments:
Post a Comment