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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:38:04+00:00 2026-06-13T16:38:04+00:00

I am trying to close all my thread in my threadpool. Usually I try:

  • 0

I am trying to close all my thread in my threadpool.

Usually I try:

        while(!Thread.currentThread().isInterrupted()) {...

To close the while loop…

But I have one Thread which only consists about

        while(!Thread.currentThread().isInterrupted()) {//which is true

This is how I close the threads:

pool.shutdownNow();

So how would you close such a Thread?

  • 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-13T16:38:05+00:00Added an answer on June 13, 2026 at 4:38 pm

    You can add a volatile boolean flag.

    public class Worker implements Runnable {
    
        volatile boolean cancel = false;
        @Override
        public void run() {
    
            while (!cancel) {
                // Do Something here
            }
        }
    
        public void cancel() {
            cancel = true;
        }
    }
    

    Now you can just call

    worker.cancel();
    

    Update:

    From Java doc of shutdownNow()

    Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

    here are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt(), so any task that fails to respond to interrupts may never terminate.

    So either you will have to define your interruption policy by preserving the interrupts

      catch (InterruptedException ie) {
         // Preserve interrupt status
         Thread.currentThread().interrupt();
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all, i have a problem with trying to get 2 forms to close
I am trying to close a memcached connection to start a new one. But
All, I've got the following JS Fiddle: http://jsfiddle.net/HHtBX/11/ I'm trying to basically close all
Possible Duplicate: Cross-thread operation not valid I am trying to close the base of
I'm trying to set something up where one thread is writing a list of
http://pastebin.com/rXbeKqAa Hi all I have been trying to parse the above JSON into a
I am trying to show a spinning progress while I load some data, but
I have a table with 6 columns in it, I'm trying to fetch all
I'm trying to read a properties file /res/version.num . But all I get is
How can I start a thread which will run in the background but the

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.