Is it possible to solve deadlock in java ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Is it possible to solve deadlock in java ?

Deadlock is a condition where 2 threads wait for each other forever.

9th Mar 2017, 4:17 PM
harshal jain
harshal jain - avatar
2 Answers
+ 5
Deadlock condition ends only if one of the threads stops waiting for the resource. To do that it is needed to use locks with timeouts.
9th Mar 2017, 6:12 PM
Tamás Barta
Tamás Barta - avatar
+ 2
To avoiding Dead Lock conditions:- Avoid Nested Locks: This is the main reason for dead lock. Dead Lock mainly happens when we give locks to multiple threads. Avoid giving lock to multiple threads if we already have given to one. Avoid Unnecessary Locks: We should have lock only those members which are required. Having lock on unnecessarily can lead to dead lock. Using thread join: Dead lock condition appears when one thread is waiting other to finish. If this condition occurs we can use Thread.join with maximum time you think the execution will take.
23rd Nov 2017, 9:31 AM
Wasula Benjamin
Wasula Benjamin - avatar