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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:56:04+00:00 2026-06-16T04:56:04+00:00

I found this solution to know if a thread has been interrupted. public class

  • 0

I found this solution to know if a thread has been interrupted.

public class OurThread extends Thread(){
    private volatile boolean stop = false;
    public void run(){
        while (!stop) {
             //Do your actions
        }
     }
 }

But my run method is only executed once, so It doesnt make sense to put it insisde a while loop. Another approach I found, is to check the Thread.isInterrupted() flag, and then terminate the thread. My run() method is pretty long so I would have to check lots of times this condition making my code dirty.

I have to apply this into four diferents processes so im trying to find a simpler, cleaner soution. I was hoping if is there something like:

try{//my code}
catch(interrumption)

The problem is that since my thread is interrumped by using future.cancel(), the interruption is not thrown inside my run() code, then i cant do that either.

Any suggestion?
By now im checking lots of times between the code if the thread has been cancelled.
Thanks 🙂

  • 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-16T04:56:06+00:00Added an answer on June 16, 2026 at 4:56 am

    Firstly, don’t extend Thread, you should implement Runnable or Callable.

    Secondly you can add a method like

    static void checkInterrupt() {
        if(Thread.currentThread().isInterrupted()) 
             throw new IllegalStateException("Interrupted");
    }
    

    and place this in the four places. This doesn’t add much code and isn’t as ugly as a task which won’t stop.

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

Sidebar

Related Questions

I know people asked this before and I found this solution: for (UIView *subview
i know every web-developer hates this topic, but anyway... i found no good solution
I have been searching for a solution to this and so far found nothing
I've been looking around for a solution to this thing but I haven't found
I searched for an implementation of std::map runtime ordering and have found this solution:
I've search for some solution to my problem and I found this link .
I found the solution for this question in C# , but I can't translate
Edited to Add * I haven't found a solution for this one yet, can
Edited: SOLUTION FOUND. This is strange and not the best solution, but I just
I edited this question after i found a solution... i need to understand why

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.