Invalid java service plus synchronized

as mentioned, I am a distributed project. Now we need to do a card grabbing function. Want to modify a method with synchronized and lock it, but the result is not optimistic

clipboard.png

clipboard.png

I call the receiveVipCard () method of another service from one service, and at first I will determine whether I can get it or not.
my test method is: change the number of cards that can be picked up to 1, and then grab the two phones together, and get both (after the grab, I will take the number of cards that can get-1), but the number of cards that can be received is 0, that is, it is reduced only once, why? Can"t distributed locks be like this?

Apr.10,2021

you have to belong to a database transaction


= my answer =
this is a distributed transaction, not with synchronized, but with distributed locks. There are mainly database-level, redis and zookeeper locks. This time I used redis to implement.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34fae-2bf64.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34fae-2bf64.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?