Scheduling tasks to run at regular intervals
I'd like to run a background task once every hour or so. I know how to fire a background task through the Application class, but I can't figure out how I can schedule a task to run at regular intervals. Is this possible / allowed?
Please sign in to leave a comment.
You can use AppExecutorUtil.getAppScheduledExecutorService().scheduleWithFixedDelay and do whatever you like inside.
Thanks, that is exactly what I've been looking for. Is this covered by documentation? I've been going through the docs quite a while and feel stupid if it is ;)
Yes, scheduleWithFixedDelay is a JDK method and so it's covered by JDK documentation. getAppScheduledExecutorService is just an instance of a ScheduledExecutorService with some special properties (also described in the javadoc), but you could create/use any other executor as well.