Figure 20.19 shows two transactions, T17 and T18, that are deadlocked because each is waiting for the other to release a lock on an item it holds. At time t2, transaction T17 requests and obtains an exclusive lock on item balx, and at time t3 transaction T18 obtains an exclusive lock on item baly. Then at t6, T17 requests an exclusive lock on item baly. Since T18 holds a lock on baly, transaction T17 waits. Meanwhile, at time t7, T18 requests a lock on item balx, which is held by transaction T17. Neither transaction can continue because each is waiting for a lock it cannot obtain until the other completes. Once deadlock occurs, the applications involved cannot resolve the problem. Instead, the DBMS has to recognize that deadlock exists and break the deadlock in some way.
Unfortunately, there is only one way to break deadlock: abort one or more of the
transactions. This usually involves undoing all the changes made by the aborted trans-action(s). In Figure 20.19, we may decide to abort transaction T18. Once this is complete,the locks held by transaction T18 are released and T17 is able to continue again. Deadlock
should be transparent to the user, so the DBMS should automatically restart the aborted
transaction(s).