Java Reference
In-Depth Information
}
}
void instanceMethod2()
{
synchronized(lock2)
{
synchronized(lock1)
{
System.out.println("second
thread
in
in-
stanceMethod2");
// critical section guarded first by
// lock2 and then by lock1
}
}
}
public static void main(String[] args)
{
final Deadlock dl = new Deadlock();
Runnable r1 = new Runnable()
{
@Override
public void run()
{
while(true)
dl.instanceMethod1();
}
};
Thread thdA = new Thread(r1);
Runnable r2 = new Runnable()
{
@Override
public void run()
{
while(true)
dl.instanceMethod2();
}
Search WWH ::




Custom Search