Written in synchronized so that can ensure that the insert is the highest price? How to ensure that the price is high?
Public synchronized String maxPrice (String price) {
String MSG="" :
//for database query operation
Int count=priceService. SelectMax (price);
If (count> 0 {
MSG="please bid again, not the highest";
} else {
//inserted into the database
PriceService. AddPrice (price);
MSG="successful bidder";
}
}
Do not need to consider performance, to make the factory project estimates and auction of only a few people.
CodePudding user response:
You had better use redis distributed lock to do itCodePudding user response:
Single-machine environment can be clustered or distributed environment requires a distributed lockCodePudding user response:
Can use the websocket to do ah, have a new price on real-time pushed to the front page, websocket push can try GoEasy, address: https://www.goeasy.io/