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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:36:56+00:00 2026-06-15T15:36:56+00:00

I have created a class which extends Thread. This class has several methods defined,

  • 0

I have created a class which extends Thread.

This class has several methods defined, some of which use Process and IO streams to download files (sometimes taking several minutes).

I also have a JButton which I use to stop the thread, it has an ActionListener which currently performs a ClassName.this.stop(); and this works perfectly.

Within the ‘public void run()’ method, I execute some of these methods and start the thread.

My question is, how can I replace my deprecated Thread.stop() method with an interrupt(), and use it to cleanly stop the thread?

I have looked at some solutions, which recommend using a boolean flag to check whether the thread has been interrupted, but seeing that the run() method simply executes a series of methods, the loop does not evaluate until all the methods have finished executing, and even then, I get a ‘InterrupedException’ and then the loop starts again.

Another issue is that if a download is in progress, it could take minutes for the download to complete and for the next check to see if the Thread has been interrupted. I’d like everything to stop and for the object to ‘delete itself and everything in it’, which is what Thread.stop() is currently doing correctly.

Any ideas anyone?

  • 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-15T15:36:57+00:00Added an answer on June 15, 2026 at 3:36 pm

    Don’t use extra boolean sentinel flags, rely fully on the interruption mechanism. In long-runnig tasks which don’t spend time in interruptible blocking methods; you must handcode occasional checks of Thread.interrupted() and break out of the task if true. If your loop goes on after InterruptedException, then fix this behavior. This aspect is completely in your hands. Don’t ignore the exception; react by curtailing the work and ending the method.

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

Sidebar

Related Questions

So I have this class that extends the Thread class. I use the thread
I have created a class which extends View class. public class SplashScreen extends View
I have created a class which extends Gallery. There is no onCreate() method in
So I have created a global class which extends globalsettings: public class Global extends
In Java I have created the following class which extends ImageView to create a
I have created an asynchronous task like this: private class LongOperationcheckall extends AsyncTask<String, String,
I have created a some testcases and use an ActiveTestSuite to run the methods
I have a method like this in my class which extends Activity @Override public
I have a simple class which does some calculations in its own thread and
I have a thread which extends Thread. The code looks a little like this;

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.