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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:22:17+00:00 2026-05-23T17:22:17+00:00

I have a thread which has an incoming job queue (a LinkedList containing job

  • 0

I have a thread which has an incoming job queue (a LinkedList containing job descriptions). The thread blocks with wait() on the queue when there’s no job to work on. An external job dispatcher object awakes it with notify() when it places new jobs on the queue.

At shutdown of my program i call interrupt() on the Thread. This raises InterruptedException when the Thread awaits for jobs in wait(). My question is: what will happen if i interrupt the Thread while it’s not blocking but doing some kind of work, the processed item was the last in the queue (so queue is now empty) and execution pasts the isInterrupted() check before the interrupted flag is set so it calls wait() again? Will it throw an InterruptedException because the interrupted flag has already been set or the thread waits forever because new jobs will never arrive to the queue and there’s no one to interrupt the wait?

  • 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-23T17:22:18+00:00Added an answer on May 23, 2026 at 5:22 pm

    yes, your interrupted thread will throw an InterruptedException upon calling wait(). this is pretty simple to test for yourself.

    public class TestInt {
        public static void main(String[] args) throws Exception
        {
            Thread.currentThread().interrupt();
    
            synchronized(TestInt.class) {
                TestInt.class.wait();
            }    
        }    
    }
    

    also, note the javaodc for Object.wait():

    InterruptedException – if any thread interrupted the current thread before or while
    the current thread was waiting for a notification. The interrupted status of the current
    thread is cleared when this exception is thrown.

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

Sidebar

Related Questions

I have a class (NamedPipeManager) which has a thread (PipeThread) that waits for a
I have a layered application in Java which has a multi thread data access
I have a DirectoryMonitor class which works on another thread. It has the following
I have a Thread model which has a show page, and in that action's
I have a Thread document which has within it Comments, which are EmbeddedDocuments. I
I have a game which has surfaceview and running on a thread. if I
I found this thread which basically has the same issue I have. But their
I have a C program which has multiple worker threads. There is a main
I have an Android application which has the main UI thread, and several other
I have a thread which handles all the HTTP Connections to the server and

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.