Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,28 @@ public class SchedulerTimerTask extends TimerTask {
private static final Logger LOGGER = LoggerFactory.getLogger(SchedulerTimerTask.class);

private final Runnable task;
private final boolean terminateOnError;

public SchedulerTimerTask(Runnable task) {
this(task, true);
}

public SchedulerTimerTask(Runnable task, boolean terminateOnError) {
this.task = task;
this.terminateOnError = terminateOnError;
}

public void run() {
try {
this.task.run();
} catch (Error error) {
// Very bad error. Can't swallow this but can log it.
LOGGER.error("Scheduled task error", error);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the log should include the value of the terminateOnError flag here

if (terminateOnError) {
LOGGER.error("Exiting JVM due to error: {}", error.getMessage());
System.exit(1);
}
throw error;
} catch (Exception exception) {
} catch (Throwable exception) {
// It is a known issue of java.util.Timer that if a TimerTask.run() method throws an exception, the
// Timer's thread exits as if Timer.cancel() had been called. This makes the Timer completely unusable from
// that point on - whenever the Timer triggers there is an 'IllegalStateException: Timer already cancelled'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public synchronized void startConnectCheckTask(long connectionTimeout) {
connectCheckerTask = new SchedulerTimerTask(connectChecker);

synchronized (AbstractInactivityMonitor.class) {
if (CHECKER_COUNTER == 0) {
if (CHECKER_COUNTER == 0 || READ_CHECK_TIMER == null) {
if (ASYNC_TASKS == null || ASYNC_TASKS.isShutdown()) {
ASYNC_TASKS = createExecutor();
}
Expand Down
Loading