I am currently having the need of using pessimistic lock in my vending machine project. When more than 1 person is choosing their products, I would like to use the pessimistic lock to prevent both people from selecting the same product. My project is Java, Spring Boot.
Is it possible for me to execute the "lock" of the pessimistic lock in one method call and somehow "unlock" the pessimistic lock in another method call? (The "lock" process is executed when the user confirms the product, and the "unlock" process is executed when the user either pays for the products or desire to re-choose the products.) Or are there any better solutions to this problem?