#1: It is bad practice to do like: try{ Thread.sleep(500); }catch (Exception e){} } How will you come to know what happened of exception if thrown!
#2: Root of deadlock: DeadLock t1 = new DeadLock(obj1, obj2); DeadLock t2 = new DeadLock(obj2, obj1);
The order or resources, the thread will work with: ->t1 will first acquire the lock of resourceA(obj1) and then go to grab the lock for resourceB(obj2). ->t1 will first acquire the lock of resourceA(obj2) and then go to grab the lock for resourceB(obj1).
Meanwhile if both the threads are having lock on one-one object, then they will wait for the other object that can't be released. Waiting for each other.