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

  • Home
  • SEARCH
  • 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 3425306
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:34:41+00:00 2026-05-18T06:34:41+00:00

I have a task which I schedule to run periodically via ScheduledThreadPoolExecutor.scheduleAtFixedRate(task, rate, …)

  • 0

I have a task which I schedule to run periodically via ScheduledThreadPoolExecutor.scheduleAtFixedRate(task, rate, …). A user can cancel this task manually, which invokes ScheduledFuture.cancel(true). For some reason, perhaps depending on when they cancel this task, the worker thread (which the executor used to run my task) appears to remain in an interrupted status after my task’s run() method exits.

I would have though that worker threads (taken from a pool and reused) would have their interrupted status cleared before starting a new task using the existing hooks (via ThreadPoolExecutor.beforeExecute() or ThreadPoolExecutor.afterExecute()). But it does not do this in the default implementation.

I have two questions:

  • How is it that the worker thread is left in a state where the interrupt status is set?
  • Why does the default implementation not clear the interrupt status before starting a new task?
  • 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-18T06:34:42+00:00Added an answer on May 18, 2026 at 6:34 am
    * How is it that the worker thread is left in a state where the interrupt status is set?
    * Why does the default implementation not clear the interrupt status before starting a new task?
    

    The answers are:

    • It is not left in an interrupted state.
    • The implementation does but you are not looking in the right spot

    From the Oracle library code:

            /*
             * Ensure that unless pool is stopping, this thread
             * does not have its interrupt set. This requires a
             * double-check of state in case the interrupt was
             * cleared concurrently with a shutdownNow -- if so,
             * the interrupt is re-enabled.
             */
            if (runState < STOP &&
                Thread.interrupted() &&
                runState >= STOP)
                thread.interrupt();
    

    As you can see, the interrupt state is cleared from the worker thread so long as the executor is not shutting down.

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

Sidebar

Related Questions

No related questions found

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.