I've got a thread in charge of periodically refreshing some remote service queries response cache every 10-15 minutes.
The problem is when a client's machine resumes from sleep the refresh task executes sleep time / refresh period times instead of just once.
It's not overloading the server or anything, but it is inefficient. How can I prevent this from happening?
Assuming the task is scheduled at a fixed rate via the ScheduledExecutorService, change the task to a self-scheduling task. In this manner there is always only 1 task waiting to be executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With