Schedule to Run Once, or Keep Running
You can specify how your task is run by setting a delay until it starts, and setting whether it should be run just once or keep running. Have a look at the first thing we do in our constructor: the call to super at ③. The call to super will in turn call the constructor in the parent class, ServerTask, with the needed information.
The ServerTask constructor takes three arguments: the server itself, a delay to wait before running, and a boolean flag that should be true if this task should keep running continuously, or false if it should be run only once (a one-shot). If you set it to run continuously, the task will run forever until you cancel it.
We could change the previous example to delay for 60 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access