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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:49:12+00:00 2026-05-19T21:49:12+00:00

I’ve been reading around about InterruptedException, and it’s immediately apparent that there’s no silver

  • 0

I’ve been reading around about InterruptedException, and it’s immediately apparent that there’s no silver bullet solution to handle it properly in all cases.

What I haven’t seen yet, is some sample code demonstrating what can go wrong if the exception is handled improperly. Of course I realize some of the effects (such as thread starvation, which I think is one of them) are hard to demonstrate. I want to keep it limited to demonstrating the proper use of Thread.sleep().

How would you go about designing a somewhat realistic sample program for this?

Here are my ideas so far:

  1. Make a simple GUI application to demonstrate reduced responsiveness. There’d be a UI thread, and a simple thread pool to perform some blocking task. The thread pool manager checks the interrupted status of the running threads to manage them. Swallowed InterruptedExceptions cause the pool to run out of threads, so the application becomes less responsive.

    This can help point out the different handling strategies for when sleeping in a managed thread vs. an unmanaged one.

  2. Have a bunch of threads that create garbage and sleep. There would be two types of threads: ones that restore the interrupted status when interrupted, and those that don’t (swallow the exception). Then the demonstration would be to run the application in a JVM with little memory, and (hopefully) show that swallowing the exception somehow inhibits garbage collection or increases its overhead (due to long interval between invocations).

Do these ideas make sense? Any other (maybe simpler) ideas?

  • 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-19T21:49:13+00:00Added an answer on May 19, 2026 at 9:49 pm

    Say you have a Thread which you want to be able to shutdown by interrupting it.

    public void run() {
       while(!Thread.currentThread().interrupted()) {
           doWork();     
           callMethodWhichIgnoresInterrupted();
       }
    }
    

    By discarding the interrupt, you can have a thread which sometimes fails to die causing a resource leak you cannot fix without restarting the application.

    Ignoring any exception is a very bad idea 95+% of the time. This is why they are checked exceptions in Java. These problems are not limited to interrupts.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites 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.