A deadlock occurs when two or more threads wait forever for a lock or resource held by another of the threads. An application may stall or fail as the deadlocked threads cannot progress.For instance, if thread 1 locks A, and tries to lock B, and thread 2 has already locked B, and tries to lock A, a deadlock arises. Thread 1 can never get B, and thread 2 can never get A. In addition, neither of them will ever know. They will remain blocked on each their object, A and B, forever. This situation is a deadlock.The situation is illustrated below:
Thread 1 locks A, waits for B
Thread 2 locks B, waits for A
#programming #java #software-development #software-engineering #java concurrency: deadlock #java concurrency