public class Locker extends Thread { private Locker other; public void setOther(Locker other) { this.other = other; } public void run() { synchronized(this) { synchronized(this.other) { // do nothing } } System.out.println("done"); } }