In the previous examples with executors, the tasks were executed once, and they were executed as soon as possible. The executor framework includes another 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 an RSS feed reader. This is a simple case where you need to make the same task (reading the news of an RSS feed) at a certain time. Our example will have the following characteristics:
- Store the RSS sources in a file. We have chosen news about the world from some important newspapers such as The New York Times, the Daily News, or The Guardian.
- We sent a
Runnableobject to the executor per RSS source. Every time the executor runs each one, it parses the RSS source and converts them to a list of