You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+16
Original file line number
Diff line number
Diff line change
@@ -4075,3 +4075,19 @@ From Openjdk JEP359:
4075
4075
4076
4076
-[Batch Inserts In Spring Boot Style Via `CompletableFuture` And Return `List<S>` (1)](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchInsertsCompletableFutureReturnList)
4077
4077
-[Batch Inserts In Spring Boot Style Via `CompletableFuture` And Return `List<S>` (2)](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchInsertsCompletableFutureReturnGivenList)
278.**[How to simulate a deadlock](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootDeadlockExample)**
4082
+
4083
+
**Description:** This application is an example of causing a database deadlock in MySQL. This application produces an exception of type: `com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction`. However, the database will retry until one of the transaction (A) succeeds.
4084
+
4085
+
**Key points:**
4086
+
- start *Transaction (A)* and trigger a `SELECT` with `PESSIMISTIC_WRITE` to acquire an exclusive lock to table `author`
4087
+
-*Transaction (A)* update `author` genre with success and sleeps for 10s
4088
+
- after 5s, start a concurrent *Transaction B* that trigger a `SELECT` with `PESSIMISTIC_WRITE` to acquire an exclusive lock to table `book`
4089
+
-*Transaction (B)* update `book` title with success and sleeps for 10s
4090
+
-*Transaction (A)* wakes up and attempt to update the book but it cannot acquire the lock holded by *Transaction (B)*
4091
+
-*Transaction (B)* wakes up and attempt to update the author but it cannot acquire the lock holded by *Transaction (A)*
4092
+
- DEADLOCK
4093
+
- database retry and succeeds after *Transaction (B)* releases the lock
0 commit comments