Which of the following is the best practice to reduce deadlock situations?
A. Access resources in the same order whenever possible within transactions B. Collect and verify input data from users before opening a transaction C. Keep transactions long. D. All of the above. E. Only A and B.
The correct answer is option A
A deadlock occurs when the first process is waiting on a resource held by the second process. Each process is stuck waiting for each other to release a resource. Unless one process is stopped, the lock remains.
Deadlock often occurs when several long running transaction execute concurrently. Therefore, avoid long transactions.
Deadlocks can also occur if the resources are not acquired in a well-defined order; therefore, it is best to access resources in the same order whenever possible within transactions.
Hope this helps.