This Spring Boot project shows how the deadlock in database can occur when data are written into 2 tables simultaneously and how can be prevented by locking the tables. Application doesn't do much - run JUnit tests to observe.
- Docker and Docker Compose
- Java
- Maven
Run and setup MS SQL DB:
docker-compose up
Compile and run JUnit tests:
mvn clean test
All tests should pass. Check the difference between DbDeadLockingServiceTest.writeBothOppositeOrderAlphaBeta
and DbNotDeadLockingServiceTest.writeBothOppositeOrderAlphaBeta
- same test but one throws DB deadlock exception, the other one does not.
docker-compose down
- MS SQL TABLOCKX - MS SQL documentation for locking the tables