Deadlock of thread
Deadlock is a part of multithreading. When a thread has locked an object and waiting for another object to be released by another thread and the other thread is also waiting for the first thread to release the first object, both threads are waiting for each other to release the lock. This condition is called thread deadlock.
Avoiding deadlocks in program
This is no specific solution for the problem of deadlock. It depends on the logic used by the programmer.
For example, in the preceding program, if the programmer used the threads in such a way that the cancelticket thread follows the bookticket, then he could have avoided the deadlock situation.
For this, we change the code in the cancelticket class, cancelticket should be changed as should here: