Title: Monitor Java scheduled jobs: Spring @Scheduled and Batch
Open Graph Title: Monitor Java scheduled jobs: Spring @Scheduled and Batch
X Title: Monitor Java scheduled jobs: Spring @Scheduled and Batch
Description: Java cron job monitoring: a Spring @Scheduled try/catch pings LastPing on success and /fail on exception; a Spring Batch listener covers batch steps.
Open Graph Description: Spring @Scheduled: try/catch that pings on success and /fail on exception. Spring Batch: JobExecutionListener for completed vs failed status. Free, no monitor cap.
X Description: Spring @Scheduled: try/catch that pings on success and /fail on exception. Spring Batch: JobExecutionListener for completed vs failed status. Free, no monitor cap.
Mail addresses
hello@lastping.dev
Opengraph URL: https://lastping.dev/monitor/java/
Domain: lastping.dev
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://lastping.dev/#org",
"name": "LastPing",
"url": "https://lastping.dev/",
"logo": "https://lastping.dev/icon-512.png",
"email": "hello@lastping.dev",
"sameAs": ["https://github.com/lastping-dev/lastping-app"]
},
{
"@type": "WebSite",
"@id": "https://lastping.dev/#website",
"url": "https://lastping.dev/",
"name": "LastPing",
"publisher": { "@id": "https://lastping.dev/#org" }
},
{
"@type": "TechArticle",
"@id": "https://lastping.dev/monitor/java/",
"url": "https://lastping.dev/monitor/java/",
"headline": "Monitor Java scheduled jobs: Spring @Scheduled and Spring Batch",
"description": "How to monitor a Java scheduled job: Spring @Scheduled with try/catch pings LastPing on success and POSTs to /fail on exception; Spring Batch uses a JobExecutionListener to check BatchStatus and ping accordingly.",
"author": { "@id": "https://lastping.dev/#org" },
"publisher": { "@id": "https://lastping.dev/#org" },
"isPartOf": { "@id": "https://lastping.dev/#website" },
"datePublished": "2026-07-24",
"dateModified": "2026-07-24"
},
{
"@type": "BreadcrumbList",
"@id": "https://lastping.dev/monitor/java/#breadcrumb",
"itemListElement": [
{ "@type": "ListItem", "position": 1, "name": "Home", "item": "https://lastping.dev/" },
{ "@type": "ListItem", "position": 2, "name": "Monitoring guides", "item": "https://lastping.dev/monitor/" },
{ "@type": "ListItem", "position": 3, "name": "Monitor Java scheduled jobs", "item": "https://lastping.dev/monitor/java/" }
]
},
{
"@type": "FAQPage",
"@id": "https://lastping.dev/monitor/java/#faq",
"mainEntity": [
{
"@type": "Question",
"name": "How do I monitor a Spring @Scheduled job?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Wrap the method body in try/catch: on success, call restTemplate.getForObject on the ping URL; on exception, POST the message to the /fail endpoint and re-throw so Spring can apply its own error handling."
}
},
{
"@type": "Question",
"name": "How do I monitor a Spring Batch job?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Implement JobExecutionListener and in afterJob() check jobExecution.getStatus(). If BatchStatus.COMPLETED, GET the ping URL. Otherwise collect the failure exceptions, join them, and POST the text to /fail."
}
},
{
"@type": "Question",
"name": "Do I need a dependency like OkHttp or Apache HttpClient?",
"acceptedAnswer": {
"@type": "Answer",
"text": "No. java.net.http.HttpClient (Java 11+) handles both GET and POST without additional dependencies. RestTemplate or WebClient from Spring are convenient wrappers but not required."
}
},
{
"@type": "Question",
"name": "What if Spring's scheduler swallows the exception?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Spring's default TaskUtils.LOG_AND_SUPPRESS_ERROR_HANDLER logs the exception but suppresses it so the scheduler keeps running. The /fail ping still fires because it is sent inside the catch block before re-throwing. Configure a custom TaskScheduler error handler if you need further propagation."
}
},
{
"@type": "Question",
"name": "How do I monitor a Quartz job in Java?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Implement a JobListener and add ping calls in jobWasExecuted: check jobExecutionException for null to distinguish success from failure. The ping URL is the same; only the hook mechanism differs."
}
},
{
"@type": "Question",
"name": "What if the JVM is OOM-killed?",
"acceptedAnswer": {
"@type": "Answer",
"text": "An OOM-killed JVM sends no ping; the missing ping opens an incident after the grace window. This is the core value of absence-detection monitoring for JVM workloads."
}
},
{
"@type": "Question",
"name": "Is Java job monitoring free?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes. LastPing is free for individuals with no monitor cap. See how it compares to Healthchecks.io and Cronitor."
}
}
]
},
{
"@type": "HowTo",
"@id": "https://lastping.dev/monitor/java/#howto",
"name": "How to monitor a Java Spring scheduled job with LastPing",
"step": [
{ "@type": "HowToStep", "position": 1, "name": "Create a monitor", "text": "Log in to app.lastping.dev, create a heartbeat monitor, set the schedule to match the @Scheduled cron expression, and set a grace window." },
{ "@type": "HowToStep", "position": 2, "name": "Store the ping URL", "text": "Add lastping.ping-url=https://ping.lastping.dev/ to application.properties and inject it with @Value." },
{ "@type": "HowToStep", "position": 3, "name": "Add try/catch or JobExecutionListener", "text": "For @Scheduled: wrap the body in try/catch, GET on success, POST to /fail on exception, re-throw. For Spring Batch: add a JobExecutionListener bean that checks BatchStatus." },
{ "@type": "HowToStep", "position": 4, "name": "Configure alert channels", "text": "In the LastPing console add email, Slack, Discord, Telegram, ntfy, Pushover, Microsoft Teams, Google Chat or webhook destinations." }
]
}
]
}
| theme-color | #0c0e12 |
| color-scheme | dark light |
| og:type | website |
| og:site_name | LastPing |
| og:image | https://lastping.dev/og.png |
| og:image:width | 1200 |
| og:image:height | 630 |
| og:image:alt | LastPing operations console showing a monitor flatlining to DOWN with alert sent. |
| twitter:card | summary_large_image |
| twitter:image | https://lastping.dev/og.png |
Links:
Viewport: width=device-width, initial-scale=1
Robots: index,follow,max-image-preview:large