+ 4
Is it possible to solve deadlock in java ?
Deadlock is a condition where 2 threads wait for each other forever.
2 Antworten
+ 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.
+ 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.