How do I add events that I want to run in the future in Spring Boot?

Viewed 71

I have a Spring Boot application that uses AWS that I use to test my students on their Bash skills. And I want to allow them to start an assessment whenever they want, but it ends in 2 hours from that time.

I could use the scheduling to check every 2 minutes or so if anyone is over their time, but I was really looking to see if there was some way that I could say "run this method with these parameters in 120 minutes".

I have looked at CloudWatch, but it, like the schedule seems to be built on the idea, you will want to run something every 2 hours or 2 minutes or 2 days, etc.

Any help would be appreciated.

1 Answers

You could try this:

 TimerTask task = new TimerTask() {
        public void run() {
            System.out.println("Task performed on: " + new Date() + "n" +
              "Thread's name: " + Thread.currentThread().getName());
        }
    };
    Timer timer = new Timer("Timer");

long delay = 1000L;
timer.schedule(task, delay);
Related