The second example – executing periodic tasks
In the previous examples with executors, the tasks were executed once, and they were executed as soon as possible. The executor framework includes other executor implementation that gives us more flexibility about the execution time of the tasks. It's the ScheduledThreadPoolExecutor
class that allows us to execute tasks periodically and to execute tasks after a delay.
In this section, you will learn how to execute periodic tasks implementing a RSS feed reader. This is a simple case where you need to make the same task (reading the news of a RSS feed) at regular intervals. Our example will have the following characteristics:
- Store the RSS sources in a file. We have chosen news about the world from some ...
Get Mastering Concurrency Programming with Java 8 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.