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 699077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:20:46+00:00 2026-05-14T03:20:46+00:00

If a thread is interrupted while inside Object.wait() or Thread.join() , it throws an

  • 0

If a thread is interrupted while inside Object.wait() or Thread.join(), it throws an InterruptedException, which resets the thread’s interrupted status. I. e., if I have a loop like this inside a Runnable.run():

while (!this._workerThread.isInterrupted()) {
    // do something
    try {
        synchronized (this) {
            this.wait(this._waitPeriod);
        }
    } catch (InterruptedException e) {
        if (!this._isStopping()) {
            this._handleFault(e);
        }
    }
}

the thread will continue to run after calling interrupt(). This means I have to explicitly break out of the loop by checking for my own stop flag in the loop condition, rethrow the exception, or add a break.

Now, this is not exactly a problem, since this behaviour is well documented and doesn’t prevent me from doing anything the way I want. However, I don’t seem to understand the concept behind it: Why is a thread not considered interrupted anymore once the exception has been thrown? A similar behaviour also occurs if you get the interrupted status with interrupted() instead of isInterrupted(), then, too, the thread will only appear interrupted once.

Am I doing something unusual here? For example, is it more common to catch the InterruptedException outside the loop?

(Even though I’m not exactly a beginner, I tagged this “beginner”, because it seems like a very basic question to me, looking at it.)

  • 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-14T03:20:46+00:00Added an answer on May 14, 2026 at 3:20 am

    The idea is that an interrupt should be handled once. If an explicit InterruptedException did not clear the “interrupt” flag then most catchers for InterruptedException would have to explicitly clear that flag. Conversely, you can “unclear” the flag by self-interruption (Thread.currentThread().interrupt()). Java’s designers went for the semantics which would save keystrokes most of the time (i.e. you more often want to clear the flag than keep it set).

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

Sidebar

Related Questions

I have an object on thread A that is calling wait() while another object
I have a processing loop of the form while (true) { doWork(); Thread.sleep(SLEEP_INTERVAL); }
thread.join() will call thread.wait() , but who and when notifies (either with thread.notify() or
I have a long running task, something like: public void myCancellableTask() { while (
I have a thread which has an incoming job queue (a LinkedList containing job
When a Thread is interrupted while it's also blocking on input from a Socket's
I have a Runnable implementing class which will be run from a Executors.newFixedThreadPool Inside
If i have a thread something like this: Thread t = new Thread(myThread); t.start();
Thread A: a UI thread where the Gtkmm's message loop runs. Thread B: receives
first thread i post here. I have been searching here for answers and almost

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.