Quick revision
The short answer
Two things combine. First, catch (Exception e) does not catch Errors, so a NoClassDefFoundError, an ExceptionInInitializerError or an OutOfMemoryError escapes the task. Second, ScheduledExecutorService wraps each periodic task in a Future: when a run throws, the throwable is stored in that Future, later runs are suppressed, and nothing is logged unless someone calls get(). Tasks given to submit() behave the same way; only execute() on an ordinary pool lets the exception reach the thread's uncaught exception handler. The fix is to catch and log Throwable at the task boundary, check the Future, or wrap tasks in a logging decorator, and to monitor jobs with heartbeat metrics.
What to remember
In this answer, we saw two causes for a scheduled task that stops without a log line. catch (Exception) does not catch Errors such as NoClassDefFoundError or OutOfMemoryError, and ScheduledExecutorService stores any throwable from a periodic task in its Future and suppresses later runs, with nothing logged; submit() also captures exceptions, and only execute() on an ordinary pool reaches the uncaught exception handler. We fixed it by logging Throwable at the task boundary with a decorator, checking the Future when we have it, and adding heartbeat metrics with alerts so silent stops are noticed.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Two things combine. First, catch (Exception e) does not catch Errors, so a NoClassDefFoundError, an ExceptionInInitializerError or an OutOfMemoryError escapes the task. Second, ScheduledExecutorService wraps each periodic task in a Future: when a run throws, the throwable is stored in that Future, later runs are suppressed, and nothing is logged unless someone calls get(). Tasks given to submit() behave the same way; only execute() on an ordinary pool lets the exception reach the thread's uncaught exception handler. The fix is to catch and log Throwable at the task boundary, check the Future, or wrap tasks in a logging decorator, and to monitor jobs with heartbeat metrics.
Why this question is asked
A job that silently stops is one of the most frustrating production bugs: no error, no stack trace, no alert, just data that stopped arriving hours ago. The developer added a catch block, so they are sure every failure would have been logged. Interviewers ask this scenario because the answer combines the exception hierarchy with how executors handle exceptions, and because the monitoring fix matters as much as the code fix. In this answer, we will reproduce the silent stop, explain the two causes, find the hidden exception, fix the task, and set up monitoring so it cannot happen silently again.
1Reproducing the Silent Stop
Here is a periodic task that catches Exception, and a dependency that fails with an Error on its third run. In real systems such an Error usually comes from a static initialiser that failed earlier; here we simply throw one to simulate it.
Notice that the log simply stops. The executor thread is still alive and the application looks healthy, but the task will never run again.
2Cause 1: An Error Is Not an Exception
Throwable has two branches, Exception and Error. catch (Exception e) handles only the first. An Error such as NoClassDefFoundError, ExceptionInInitializerError, StackOverflowError or OutOfMemoryError passes straight through it.
These Errors are more common in scheduled jobs than people expect. A class used only by the job may fail its static initialisation the first time it is touched, perhaps because a configuration file is missing, which throws ExceptionInInitializerError once and NoClassDefFoundError on every later attempt. A dependency conflict can throw NoSuchMethodError, a LinkageError, only when the job's code path runs. None of these is an Exception.
3Cause 2: The Executor Stores the Failure in a Future
scheduleAtFixedRate does not run our Runnable directly. It wraps it in a ScheduledFutureTask, a Future that also knows how to reschedule itself. When a run throws anything, the wrapper catches it, stores it as the Future's result, and marks the Future done. Its documentation says that if any execution encounters an exception, subsequent executions are suppressed. Nothing is printed, because the executor assumes whoever holds the Future will look at it.
The same thing happens with submit(): the task is wrapped in a FutureTask, and a failure is stored for get() to rethrow as an ExecutionException. Only execute() on an ordinary ThreadPoolExecutor lets the throwable escape to the worker thread, where the thread's uncaught exception handler prints it. Note that ScheduledThreadPoolExecutor.execute() also wraps the task in a Future, so even execute() is silent on a scheduled executor.
6 messages in order. Play them, or step through them one at a time.
The Logger is never called: the throwable waits inside the Future.
4Finding the Hidden Exception
If the code kept the ScheduledFuture, we can ask it. isDone() is true for a periodic task only if it failed or was cancelled, and get() rethrows the stored throwable wrapped in an ExecutionException.
In production we may not have that reference. A thread dump shows the executor thread idle in its queue rather than running the task, and a heap dump would contain the Future with its stored outcome, but by far the quickest path is to add logging, as in the next section, and wait for the next failure.
5Fixing the Task Boundary
The task's outermost catch should catch Throwable, log it, and decide whether to continue. Catching Throwable here is legitimate because this is the boundary of the task, just like the top of a thread. Rather than repeating the try block in every job, we wrap every scheduled job in a small decorator.
Because the decorator does not rethrow ordinary failures, the executor keeps the schedule alive, and the next run tries again. For VirtualMachineError, rethrowing lets the failure surface, and we pair it with -XX:+ExitOnOutOfMemoryError so the process restarts cleanly. In Spring, @Scheduled methods run through a TaskScheduler whose error handler logs failures and keeps periodic tasks running by default; check your version's ErrorHandler configuration.
6Monitoring So Silent Stops Are Noticed
Logging only helps when there is something to log. A job can also stop because it hangs, because its thread pool was shut down, or because the scheduler was never started on one instance. So each job also records a heartbeat: a timestamp gauge updated at the end of every successful run, such as job.last_success_seconds. An alert fires when the heartbeat is older than two or three intervals, for example 3 minutes for a job that runs every minute. That alert catches every kind of silent stop, including ones we have not imagined yet.
- Job finishes a runupdates last_success timestamp
- Monitoring checks every minute
- Last success older than 3 intervals?YesAlert the owning teamNoAll good
- Investigate with logs and the failure counter
4 steps in order. Play them, or step through them one at a time.
7Follow-up questions
Why doesn't the executor just log the exception?
Because with a Future the design is that the submitter owns the outcome and may handle it, for example by retrying. Logging inside the executor would double-log handled failures. The cost is that unobserved Futures hide failures, which is why wrapping tasks is a common practice.
Would scheduleWithFixedDelay behave differently?
No. It also suppresses later runs once a run throws. The difference between the two methods is only how the next start time is computed.
Should we catch Throwable and keep running after OutOfMemoryError?
No. After a VirtualMachineError the JVM's state is uncertain, so the safe choice is to log, let it propagate or exit, and let the orchestrator restart the process. Catching Throwable at the boundary is for logging, not for pretending nothing happened.
8Conclusion
In this answer, we saw two causes for a scheduled task that stops without a log line. catch (Exception) does not catch Errors such as NoClassDefFoundError or OutOfMemoryError, and ScheduledExecutorService stores any throwable from a periodic task in its Future and suppresses later runs, with nothing logged; submit() also captures exceptions, and only execute() on an ordinary pool reaches the uncaught exception handler. We fixed it by logging Throwable at the task boundary with a decorator, checking the Future when we have it, and adding heartbeat metrics with alerts so silent stops are noticed.
Open with
I would suspect two things together. First, catch Exception does not catch Errors. Things like NoClassDefFoundError after a failed static initialiser, NoSuchMethodError from a dependency conflict, or OutOfMemoryError go straight past it.
Then, if they want more
Second, a ScheduledExecutorService does not log task failures. scheduleAtFixedRate wraps the task in a Future; if a run throws anything, the throwable is stored in that Future, later executions are suppressed, and nothing is printed unless someone calls get(). submit() works the same way, and only execute() on a normal ThreadPoolExecutor lets the exception reach the thread's uncaught exception handler; even execute() on a scheduled executor wraps the task.
If we kept the ScheduledFuture, isDone() returning true for a periodic task confirms it, and get() shows the cause.
To fix it, I would wrap every scheduled job in a decorator that catches Throwable at the task boundary, logs it with the job name and increments a failure counter, so ordinary failures do not kill the schedule, while VirtualMachineErrors still propagate and ExitOnOutOfMemoryError restarts the process.
Finally, I would add a heartbeat metric per job, the time of the last successful run, with an alert when it is older than a few intervals, because that catches any silent stop, not only exceptions.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A scheduled task in an ExecutorService stops running without any log line. The code...": https://scrivio-interview-library.netlify.app/java/exceptions/b8954d74e6/