Interview Questions and Answers on Deadlock

Q1.  What is a Deadlock ?

Ans. When two threads are waiting each other and can’t precede the program is said to be deadlock.

Q2.  What is database deadlock ? How can we avoid them?

Ans. When multiple external resources are trying to access the DB locks and runs into cyclic wait, it may makes the DB unresponsive. 

Deadlock can be avoided using variety of measures, Few listed below -

Can make a queue wherein we can verify and order the request to DB.

Less use of cursors as they lock the tables for long time.

Keeping the transaction smaller.