Home > Back-end >  JAVA auction time delay state how to change the goods
JAVA auction time delay state how to change the goods

Time:12-03

Bidding time-lapse scenario: if at the end of the auction end distance x minutes someone bid, the end of the activity time automatically extend back x minutes;
How to get the goods in Java into from the bidding is over? Timing task? Multithreading?

CodePudding user response:

The timeout and order processing is a similar scenario.
1. Regularly query the database/redis
2. The time round
3. DelayQueue
4. The RabbitMQ delay queue
Recommend a fourth

CodePudding user response:

This is pure algorithm problem, has nothing to do with Java,

Demand more wonderful work, or the description is not clear, the end of the auction last x minutes someone bid, why backward extend activity over time? Irrational,

Delay processing: don't need the timer, as long as someone bid, judge end mark, if has finished, bidding is invalid, otherwise the calculation time and end time of received time x, will end time delayed x,

End: this need timer, polling whether end time had come, if have to update the end mark,

In the code, some issues need to be paid attention to multithreaded variable lock

CodePudding user response:

Simply be a bid, after 30 minutes no one bid, auction closes, some offer, at this point in time again 30 minutes later,

Is similar to kill success, 30 minutes to payment mechanism,

General:
1, polling (not real-time, low performance),
2, delay queue: messages into the queue, but not to spend 30 minutes;
3, timing task, similar to delayed queue, 30 minutes after the callback, such as Quartz,

Behind the recommended two kinds of schemes,
But the large amount of data, delays in the queue, could lead to MQ memory backlog, some performance problems, or even collapse,
Third, the Quartz to register a timed task and url, make it 30 minutes to invoke this url, this is a lightweight, performance is also quite good,

CodePudding user response:

Delay would be better to use the Timer,
 

The Timer Timer=new Timer ();

Var task=new TimerTask () {

@ Override
Public void the run () {


}
};

The timer. The schedule (task, 10000); Schedule a task

Task. The cancel ();//to cancel task

The timer. The schedule (task, 10000);//to schedule a task
  • Related