DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • The Future of Java and AI: Coding in 2025
  • Tired of Spring Overhead? Try Dropwizard for Your Next Java Microservice
  • Using Python Libraries in Java
  • Designing a Java Connector for Software Integrations

Trending

  • How To Develop a Truly Performant Mobile Application in 2025: A Case for Android
  • Cosmos DB Disaster Recovery: Multi-Region Write Pitfalls and How to Evade Them
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  • Agile and Quality Engineering: A Holistic Perspective
  1. DZone
  2. Data Engineering
  3. Big Data
  4. Automate Long Running Routine Task With JobRunr and Spring Boot

Automate Long Running Routine Task With JobRunr and Spring Boot

This article will explain a simple way to deploy, manage and monitor long-running background tasks, especially ETL systems.

By 
MORRISON IDIASIRUE user avatar
MORRISON IDIASIRUE
·
Mar. 28, 23 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
6.2K Views

Join the DZone community and get the full member experience.

Join For Free

Today I shall explain a simple way to deploy, manage and monitor long-running background tasks, especially ETL systems. The common questions that every big data engineer would ask concerning a deployed ETL tool are the performance of the tool, what is causing the break in the processing pipeline, how easy it is to chain several jobs, and lots more. 

JobRunr makes it easy to schedule background long-running tasks. it is a distributed Java background job scheduler with lots of exciting features like scheduled and delayed jobs, fire and forget jobs, recurring jobs, queuing jobs and batches, and job chaining. Please note that some of these features are only available in the pro version. However, most of JobRunr's features are completely open-sourced. The library also provides a nice interface to manage and monitor all your jobs. I find this really fascinating as end users can adopt this visual for other useful purposes; for instance, from the UI, recurring jobs can be triggered manually, it provides a report on when next a job is expected to run, and users get to see nice-looking reports of each job processing time and also hardware performance information of the server where the application is deployed, isn't this exciting?

Next, let's dive into integrating JobRunr into our Java application:

Technologies Used:

  • Spring Boot
  • JobRunr
  • Jackson
  • Java 11

Start with creating a sample spring boot application; I recommend using Spring Initializr for rapid setup.

Add JobRunr to the Spring Boot Application

Add this to the list of dependencies in your pom file:

Java
 
 <dependency>
            <groupId>org.jobrunr</groupId>
            <artifactId>jobrunr-spring-boot-starter</artifactId>
            <version>${jobrunr.version}</version>
        </dependency>
        
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.11.0</version>
        </dependency>
       


Configure JobRunr to use in-memory storage. Do this by adding a bean class to your project.

Java
 
@Configuration
public class StorageProviderConfig {

    @Bean
    public StorageProvider storageProvider(JobMapper jobMapper) {
        InMemoryStorageProvider storageProvider = new InMemoryStorageProvider();
        storageProvider.setJobMapper(jobMapper);
        return storageProvider;
    }
    
}


JobRunr has an intuitive dashboard that makes it easy to monitor the status of Jobs. Add the following lines of code to your application.properties to activate the UI Dashboard.

 
org.jobrunr.background-job-server.enabled=true
org.jobrunr.dashboard.enabled=true


Next, create a simple service that would contain a logic that mimics a long-running task.

Java
 
@Service
public class SampleJobService {

    public static final long EXECUTION_TIME = 5000L;

    private Logger logger = LoggerFactory.getLogger(getClass());

    private AtomicInteger count = new AtomicInteger();

    @Job(name = "The sample job with variable %0", retries = 2)
    public void executeSampleJob(String variable) {

        logger.info("The sample job has begun. The variable you passed is {}", variable);
        try {
            Thread.sleep(EXECUTION_TIME);
        } catch (InterruptedException e) {
            logger.error("Error while executing sample job", e);
        } finally {
            count.incrementAndGet();
            logger.info("Sample job has finished...");
        }
    }
}


The job above is expected to accept an argument when called, wait for five seconds, and print "Sample job has finished." It has been configured to retry for two attempts (in case of any failure).

Finally, we need to schedule the Job we created previously. Add the following lines of code to your Spring Boot entry class.

Java
 
 @Autowired
    private JobScheduler jobScheduler;

 @PostConstruct
    public void scheduleRecurrently() {
        jobScheduler.<SampleJobService>scheduleRecurrently(Cron.every5minutes(), x -> x.executeSampleJob("a recurring job"));
    }


Voila, we have successfully scheduled the job to execute every five minutes. Run the application, and you should be able to access the JobRunr dashboard on port 8,000(the default port for JobRunr, you can change this for your needs).

JonRunr Dashboard


The purpose of this article is to give you a quick start to using JobRunr. You can build on this to develop more complex workflows; for example, it's possible to chain multiple Jobs sequentially with JobRunr. For more information, kindly visit JobRunr's official website 

Extract, transform, load Job scheduler Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • The Future of Java and AI: Coding in 2025
  • Tired of Spring Overhead? Try Dropwizard for Your Next Java Microservice
  • Using Python Libraries in Java
  • Designing a Java Connector for Software Integrations

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!