Java Multi-Threading Question:

Download Job Interview Questions and Answers PDF

Explain deadlock?

Java Multi-Threading Interview Question
Java Multi-Threading Interview Question

Answer:

When two or more threads are waiting for each other and get blocked forever then this situation is called Deadlock.
During deadlock two threads, each thread has acquired a lock on one resource and trying to acquire a lock on resource of other thread.
Each thread will wait indefinitely for the other to release the lock, unless one of the user processes is stopped.

In terms of Java API, thread deadlock situation can arise in following conditions:

1. When two threads call Thread.join() on each other.
2. When two threads use nested synchronized blocks to lock two objects and the blocks lock the same objects in different order.

Download Java Multi-Threading Interview Questions And Answers PDF

Previous QuestionNext Question
How to debug our application for issues when multiple threads are being executed?What is starvation?