I have to develop a client server architecture with Java (server side), but I need some advice.
Situation:
- a server that exposes an action decrementValue
- the server has a variable called Value = integer value
- some clients can send a decrementValue request to the server
server, for each requests, do:
-- if value > 0 value = value - 1 and answer the new val to the client-- if value = 0 answer impossible operation
So, if value = 2 and 3 request arrives at the same time, only 2 request can decrement value.
What is the best solution to do it?
How can I guarantee the exclusive access to value stored in the server, if some request are done in the same time from client to server?
Thank you.