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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:08:36+00:00 2026-05-26T10:08:36+00:00

I am reading the 7th chapter of Java Concurrency in Practice. In a section

  • 0

I am reading the 7th chapter of Java Concurrency in Practice.

In a section which speaks about methods that do not have a cancellation policy of its own but calls methods that can be interruped, the book has the following thing to say.

Activities that do not support cancellation but still call interruptible
blocking methods will have to call them in a loop, retrying when
interruption is detected.In this case, they should save the
interruption status locally and restore it just before returning,
rather than immediately upon catching InterruptedException.

I haven’t understood this fully.

Does it mean, if I call Thread.sleep in my method, I will have to call it in a loop or something?

Can anyone explain why it should be done so?

  • 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-26T10:08:37+00:00Added an answer on May 26, 2026 at 10:08 am

    I call Thread.sleep in my method, I will have to call it in a loop or something ?

    Thread.sleep() will throw an InterruptedException when the current thread is interrupted (by another thread). It’s your choice how to react to that. If you want to sleep, regardless of if someone is trying to interrupt you, then yes, you have to build some kind of loop around the try-catch block. Probably you should use a clock (e.g. System.nanoTime()) to check how long you had slept before the exception was thrown, and then continue sleeping for the remaining time etc.

    Note that InterruptedException is thrown only if another thread has interrupted the current thread, by calling (current)Thread.interrupt(). It doesn’t happen by itself, so in general you don’t need to build any loops around sleeps or anything like that. Usually threads are interrupted only for a good reason (e.g. application shutting down), so you probably want to support cancellation / interruption unless there’s no special reason not to. A “special reason” could be, for instance, writing to an I/O device and trying to guarantee that all data will be written, regardless of cancellation attempts.

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

Sidebar

Related Questions

Reading through the CKEditor documentation , I see that they have an option to
Reading up on design patterns, and have found that there are 23(?) some-odd patterns
Reading through Thinking in Java i stuck in ex:6 of Inner Classes chapter. Exercise
Reading the documentation at http://jersey.java.net/nonav/documentation/latest/client-api.html#d4e704 makes me think that ClientFilter s are processed in
Reading the Oxite source code, I have found that validators save bad property name
Reading MSDN (and other sources) about custom report items (CRI) for reporting services 2005.
reading pylons documentations I did understand that websetup:setup_app is only called when the application
Reading about the problem of creating a read only primitive vector in C# (basically,
Reading the FTP RFC (RFC959), I notice some modes that I've never seen used,
Reading some articles, told me that soft keys varies between devices. Some says -6

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.