Links for Eclipse Collection
https://piotrminkowski.com/2021/06/22/using-eclipse-collections/
https://sendilkumarn.com/blog/eclipse-collections
https://donraab.medium.com/getting-started-with-eclipse-collections-part-1-d5ba0098465f
Scheduling Distributed Jobs with JobRunr in Java
In modern application development, scheduling jobs in a distributed and scalable manner is a critical requirement. JobRunr, a modern framework for job scheduling, provides an elegant and powerful solution for scheduling background jobs in a distributed pattern using Java.
In this blog, we’ll walk through a simple use case to demonstrate how you can schedule a job to run after a specified time using JobRunr.
Setting Up JobRunr
To get started, include the necessary dependencies in your pom.xml file. Below are the Maven dependencies required for JobRunr and its integration with Jackson for serialization.
<dependency>
<groupId>org.jobrunr</groupId>
<artifactId>jobrunr</artifactId>
<version>7.3.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.11.1</version>
</dependency>
Example Use Case: Scheduling a Delayed Job
In this example, we’ll configure JobRunr to schedule a job that executes after a 60-second delay. The job will simply print a message to the console.
Here’s the sample code:
import org.jobrunr.configuration.JobRunr;
import org.jobrunr.scheduling.JobScheduler;
import org.jobrunr.storage.InMemoryStorageProvider;
import java.time.Instant;
public class JobRunrExample {
public static void main(String[] args) {
// Configure JobRunr with an in-memory storage provider
JobScheduler jobScheduler = JobRunr.configure()
.useStorageProvider(new InMemoryStorageProvider())
.useBackgroundJobServer()
.initialize()
.getJobScheduler();
// Schedule a job to run after 60 seconds
jobScheduler.schedule(Instant.now().plusSeconds(60),
() -> System.out.println("Hello!"));
}
}
Explanation
Conclusion
JobRunr simplifies the process of scheduling background tasks in Java applications, making it a great choice for distributed systems. This framework not only supports delayed job execution but also offers features like retry mechanisms, distributed execution, and integration with popular storage solutions.
Links for Eclipse Collection https://piotrminkowski.com/2021/06/22/using-eclipse-collections/ https://sendilkumarn.com/blog/eclipse-collecti...