user1865027
user1865027

Reputation: 3647

how to implement countdown trigger in server side using java?

Bidding sites like quibids and ebay has a countdown showing how much time left for the auction. I know this can be taken care on FE and should be fairly easy. What I want to know is how to do this on server side? like sending an email to people participate but didn't win and updating database when times up. I've thought about two approaches to do this.

  1. keep the timer on client side and do updates when the first request hit
  2. open a new thread and make it sleep for x amount of time then wake up to do the updates.

Both approaches don't sound right to me and will lead to issues I think. Like user will likely not getting the updates on time, or server will have lots of sleeping beauty waiting.

Upvotes: 0

Views: 1744

Answers (2)

Feras Wilson
Feras Wilson

Reputation: 390

To schedule a task, use a ScheduledExecutorService.

Upvotes: 0

Rafa
Rafa

Reputation: 2027

What I want to know is how to do this on server side? like sending an email to people participate but didn't win and updating database when times up.

The best way may vary depending of technology stack of your server side.

You if are running from a Servlet container (e.g.: Tomcat, Jboss...), you probably want to do something similar to this: Background timer task in JSP/Servlet web application

If you are running a Spring application (e.g.: Spring Boot or Spring MVC), then I recommend @Scheduled or other Task Execution and Scheduling

For advanced scenarios you may want to go with Quartz

Something else, then you should try hooking it up with Java Timer Task

Upvotes: 1

Related Questions