Java Cron Job Monitoring

Java has run the backend of the internet for decades. It is stable and scalable, but configuring monitoring for simple Java batch jobs can sometimes feel like overkill with traditional enterprise tools.

olic.io offers a lightweight alternative. We simply wait for a “heartbeat” from your Java application. No agents, no complex configuration XMLs—just a simple HTTP request.

Adding a Heartbeat to Your Java App

Since Java 11, the java.net.http.HttpClient offers a modern, clean way to make requests without needing external libraries like Apache HttpClient or OkHttp.

Implementation

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class CronMonitor {

    public static void main(String[] args) {
        String heartbeatUrl = "https://api.olic.io/ping/YOUR-ID-HERE";

        try {
            // --- YOUR CORE LOGIC HERE ---
            System.out.println("Running nightly reconciliation...");
            // ----------------------------

            // Send the success ping
            HttpClient client = HttpClient.newBuilder()
                    .connectTimeout(Duration.ofSeconds(10))
                    .build();

            HttpRequest request = HttpRequest.newBuilder()
                    .uri(URI.create(heartbeatUrl))
                    .GET()
                    .build();

            client.send(request, HttpResponse.BodyHandlers.ofString());
            System.out.println("Ping sent to olic.io");

        } catch (Exception e) {
            System.err.println("Job failed: " + e.getMessage());
            System.exit(1);
        }
    }
}

This code snippet is self-contained. You can copy it into any utility class. If you are working in a Team, this standardized approach makes it easy for anyone to debug.

Why Java for Backend Automation

Java is the heavy lifter. It is used for massive data processing tasks and widely adopted by Data Analysts and engineers for ETL (Extract, Transform, Load) processes.

Long-running Java Virtual Machine (JVM) processes can sometimes encounter memory leaks or garbage collection pauses that hang the application. By expecting a ping at a specific time, olic.io acts as an external watchdog, ensuring your critical Healthchecks are passing.

Learn more about Java here.

Need help?