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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:59:40+00:00 2026-06-08T16:59:40+00:00

I have a question regarding the implementation of a cancellation policy for a Thread

  • 0

I have a question regarding the implementation of a cancellation policy for a Thread subclass. It seems to be common practice to do it like this:

class A extends Thread {

  [...]

  public final void run() {
     try {
        while(!Thread.currentThread().isInterrupted()) {
           [...]
        }
     } catch (InterruptedException consumed) {
     }
  }

  public final void cancel() {
     interrupt();
  }    
}

The question I have is regarding Thread.currentThread()… Why is it common practice to use currentThread() for checking the interruption flag but not for setting it in the cancel() method? Wouldn’t it suffice to just call the isInterrupted() method of A like this:

while (!isInterrupted()) {
   [...]
}

I couldn’t find an answer neither in the Thread JavaDoc, Brian Goetz’ excellent book on concurrent Java or stackoverflow.

Thanks in advance for your insights!

Cheers,
Georg

  • 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-06-08T16:59:43+00:00Added an answer on June 8, 2026 at 4:59 pm

    In your case it is sufficient to just call !isInterrupted() because you’re extending from the Thread class. Typically you don’t extend from Thread – that’s why you call Thread.currentThread().

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

Sidebar

Related Questions

I have a question regarding implementation of smart-search features. For example, consider something like
I have a question regarding my database design and its implementation that i am
I have question regarding the SQLAlchemy. How can I add into my mapped class
i have a question regarding the AsyncTask class in android, and why it is
I have a question regarding the doPut method in WebdavServlet implementation in Java. If
enter code hereI have a basic question regarding an implementation using a Axis2 web
I have a question regarding the FractionRgbData class of Neuroph ImageRecognition of Neuroph 2.6.
I have a question regarding the native Array.forEach implementation of JavaScript: Does it behave
This is a design question regarding an MVC implementation. I am creating a 2D
I have a question regarding the implementation of loadView: Right now, I have it

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.