Home > Back-end >  Websocket push for bidding, how to ensure not oversold?
Websocket push for bidding, how to ensure not oversold?

Time:09-29

Make a judgment before pushed to the server, with ajax queries under the guarantee is the highest price
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 it

CodePudding user response:

Single-machine environment can be clustered or distributed environment requires a distributed lock

CodePudding 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/
  • Related