Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 950071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:30:25+00:00 2026-05-15T23:30:25+00:00

The other day I was implementing an important service in my application, that should

  • 0

The other day I was implementing an important service in my application, that should continue to run no matter what. So I used the following construct:

ScheduledExecutorService ses =
Executors.newSingleThreadScheduledExecutor();

//If the thread dies, another will take over
ses.scheduleAtFixedRate(importantPeriodicTask, 1, 1, TimeUnit.NANOSECONDS);

…only to find out that when importantPeriodicTask acutually throws a RuntimeException or Error, the ScheduledExecutorService will stop executing this task (they will cease to be scheduled).

This is of course exactly what the javadoc says:

If any execution of the task
encounters an exception, subsequent
executions are suppressed.

So shame on me, but I couldn’t understand why the authors implemented ScheduledExecutorService like this.

Granted, a RuntimeException or Error should generally not be caught, especially Error. But in reality, especially in case of RuntimeException, truth is that they are thrown quite common in production deployment, and I feel it is almost always desirable that while that particular operation should fail, the app itself should not fail because of that isolated error.

It is true that a suppression of one periodic task does not affect other kinds of periodic tasks. But given the nature of most periodic tasks, shouldn’t these tasks perceived as a “service”, rather than isolated tasks?

In other words, shouldn’t only that one instance of importantPeriodicTask fail, and the task itself be continued to be rescheduled?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:30:25+00:00Added an answer on May 15, 2026 at 11:30 pm

    In my opinion the current behavior is reasonable. RuntimeExceptions usually refer to bugs. They can practically occur anywhere in the task’s code. If the task is stateful for example, it may leave its state inconsistent, and subsequent executions will have an unexpected behavior. In general, I don’t like code that tries to recover from its own bugs, but that’s my opinion.

    If you wish to change the behavior of ScheduledExecutorService, take a look at the following generic solution:

    http://www.javaspecialists.eu/archive/Issue154.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The other day I noticed that if I run IEInspector's HttpAnalyser and capture the
the other day a colleague of mine stated that using static classes can cause
The other day, I came across this construct: static_cast<size_type>(-1) in some example C++ code,
It struck me the other day that I know nearly nothing about the hardware
I was discussing with a co-worker the other day the similarities of implementing a
I realized the other day that most common lisp had 128-bit long-floats. As a
Someone asked me the other day when they should use the parameter keyword out
The other day I set up an Ubuntu installation in a VM and went
The other day I decided to write an implementation of radix sort in Java.
The other day, I tweaked a script for a friend's World of Warcraft addon.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.