1   import java.lang.Thread;
2   
3   public class T {
4       private static Object l1 = new Object();
5       private static Object l2 = new Object();
6       public static void main(String[] args) {
7           // thrd 1
8           Thread thrd1 = new Thread() {
9               public void run() {
10                  foo();
11              }
12          };
13          thrd1.start();
14  
15          // thrd 2
16          Thread thrd2 = new Thread() {
17              public void run() {
18                  bar();
19              }
20          };
21          thrd2.start();
22      }
23      private static void foo() {
24          synchronized (l1) {
25              baz();
26          }
27      }
28      private static void baz() {
29          synchronized (l2) {
30              // ...
31          }
32      }
33      private static void bar() {
34          synchronized (l2) {
35              taz();
36          }
37      }
38      private static void taz() {
39          synchronized (l1) {
40              // ...
41          }
42      }
43  }
44  
45