## CHAPTER 8 Periodic Job 

The Periodic Job  pattern extends the Batch Job  pattern by adding a time dimension and allowing the execution of a unit of work to be triggered by a temporal event. 

## Problem 

In the world of distributed systems and microservices, there is a clear tendency toward real-time and event-driven application interactions using HTTP and light‐ weight messaging. However, regardless of the latest trends in software development, job scheduling has a long history, and it is still relevant. Periodic Jobs  are commonly used for automating system maintenance or administrative tasks. They are also rele‐ vant to business applications requiring specific tasks to be performed periodically. Typical examples here are business-to-business integration through file transfer, application integration through database polling, sending newsletter emails, and cleaning up and archiving old files. 

The traditional way of handling Periodic Jobs  for system maintenance purposes has been the use of specialized scheduling software or Cron. However, specialized soft‐ ware can be expensive for simple use cases, and Cron jobs running on a single server are difficult to maintain and represent a single point of failure. That is why, very often, developers tend to implement solutions that can handle both the scheduling aspect and the business logic that needs to be performed. For example, in the Java world, libraries such as Quartz, Spring Batch, and custom implementations with the ScheduledThreadPoolExecutor  class can run temporal tasks. But similarly to Cron, the main difficulty with this approach is making the scheduling capability resilient and highly available, which leads to high resource consumption. Also, with this approach, the time-based job scheduler is part of the application, and to make the scheduler highly available, the whole application must be highly available. Typically, that involves running multiple instances of the application, and at the same time, 

