Just a demonstration project
./gradlew clean
./gradlew build
./gradlew bootrun
Open browser at http://localhost:8080/h2-console.
Login using credentials username demo
, password demo
.
It is to demonstrate how to use Pessimistic lock on a locking table to achieve consistent testing of number of records before insertion in an atomic transactional manner
- Start up the web application. Refer to How to run web project.
- Open the browser and login to the h2 database console.
- Select all rows from the voucher table. It should shows empty rows.
- Using a terminal shell, run the following codes:
This will ensure there are 1000 concurrent processes trying to obtain vouchers from the system.
for i in `seq 1 1000`; do curl -s http://localhost:8080/voucher/request?userid=$[ $RANDOM % 100 ] >/dev/null & done
- Once step (4) is done, use the h2 database console, run the following query to find out
the number of vouchers requested for each user.
It should shows that each user(user_id) should have at most 2 vouchers issued.
select user_id, count(*) from voucher group by user_id;