Back to project page androidcodes.
The source code is released under:
GNU General Public License
If you think the Android project androidcodes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.java.thread; //from w w w .j a v a 2s . c o m import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; class A { private int a; private String b; } class B { private int a; private String b; } public class DeadLock { public static void main(String[] args) { final A a = new A(); final B b = new B(); Thread t1 = new Thread(new Runnable() { @Override public void run() { synchronized (b) { System.out.println("current thread with lock b" + Thread.currentThread()); } synchronized (a) { System.out.println("current thread with lock a" + Thread.currentThread()); } } }); Thread t2 = new Thread(new Runnable() { @Override public void run() { synchronized (a) { System.out.println("current thread with lock b" + Thread.currentThread()); } synchronized (b) { System.out.println("current thread with lock a" + Thread.currentThread()); } } }); t1.start(); t2.start(); } }