//wait as long as the argument suggests (or use 20 ms as default)
int wait = args.length == 0 ? 20 : Integer.parseInt(args[0]);
Deadlock d1 = new Deadlock();
Deadlock d2 = new Deadlock();
//make sure the Deadlock objects know each other
d1.init("d1", d2);
d2.init("d2", d1);
Thread d1Thread = new Thread(d1);
Thread d2Thread = new Thread(d2);
//Start the first thread, then wait as long as
//instructed before starting the other
d1Thread.start();
try {Thread.sleep(wait);}
catch (InterruptedException e) {}
d2Thread.start();