1. It two threads are waiting for each other forever,this situation is called “Deadlock“.
  2. For deadlock,there is no resolution techniques but several prevention techniques are possible
  3. .

Example:

class A{
	public synchronized void foo(B b){
		System.out.println("Thread1 entered into foo method");{
		try{
			Thread.sleep(5000);
		}catch(InterruptedException ie){
			
		}
		System.out.println("Thread1 trying to call B's last method");
		b.last();
		}
	}
	
	public synchronized void last(){
		System.out.println("This is A's last method");
	}
}


class B{
	public synchronized void bar(A a){
		System.out.println("Thread2 entered into bar method");{
		try{
			Thread.sleep(5000);
		}catch(InterruptedException ie){
			
		}
		System.out.println("Thread2 trying to call A's last method");
		a.last();	
		}
	}
	
	public synchronized void last(){
		System.out.println("This is B's last method");
	}
}



public class DeadLock implements Runnable{
	A a=new A();
	B b=new B();
	
	DeadLock(){
		Thread t=new Thread(this);
		t.start();
		a.foo(b);
	}
	public void run() {
		b.bar(a);
		
	}

	public static void main(String[] args) {
		new DeadLock();
	}
}
/*
Output:
Thread1 entered into foo method
Thread2 entered into bar method
Thread1 trying to call B's last method
Thread2 trying to call A's last method
//went to deadlock state

*/