0

I would like to create a Spring Boot application and let it run exactly 24 hours. After that the application should exit nicely. I could only think of achieving this goal with an infinate loop and always check current time equals start time + 24 hours. Can anybody please advise?

Please note this is NOT to schedule some tasks...

LOUDKING
  • 301
  • 1
  • 13

2 Answers2

2

You can schedule a task to execute once: (Spring scheduling task - run only once) and close application when task is executed (Programmatically shut down Spring Boot application)

piradian
  • 414
  • 7
  • 19
1

If you do this on Linux, you can run your Spring Boot Application, and get the process ID.

java -jar your-app.jar

and use another base script to kill it after 24 hours, like :

sleep 24 * 60 * 60
kill -9 <pid_of_your_app>
vonzhou
  • 339
  • 1
  • 5