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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:42:05+00:00 2026-06-06T09:42:05+00:00

What the right way to interrupt executor’s thread? I’ve got this: Thread class with

  • 0

What the right way to interrupt executor’s thread?
I’ve got this:
Thread class with name Worker with method:

public void run() {
    while(!(Thread.currentThread().isInterrupted()){
        System.out.println("work " + Thread.currentThread().getName() + ":" + Thread.currentThread().isInterrupted());
    }
}

And main class with:

ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
Worker worker = new Worker();                   
executorService.execute(worker);  

I try to call worker.interrupt(); or executorService.shutdownNow(); but my thread goes on and isInterrupted() is false.

  • 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-06T09:42:06+00:00Added an answer on June 6, 2026 at 9:42 am

    Can you post all the relevant code? Based on the information you have given, I can’t reproduce the behaviour you describe. See below a SSCCE that works as expected – output:

    work pool-1-thread-1:false
    work pool-1-thread-1:false
    work pool-1-thread-1:false
    ….
    Thread has been interrupted

    Code:

    public class Test {
    
        public static void main(String[] args) throws InterruptedException {
            ExecutorService executorService = Executors.newFixedThreadPool(1);
            Worker worker = new Worker();
            executorService.execute(worker);
            executorService.shutdownNow();
        }
    
        public static class Worker extends Thread {
    
            public void run() {
                while (!Thread.currentThread().isInterrupted()) {
                    System.out.println("work " + Thread.currentThread().getName() + ":" + Thread.currentThread().isInterrupted());
                }
                System.out.println("Thread has been interrupted");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this the right way to do a nested navigation? <dl> <dt>Struktur</dt> <dd> <ul
Is this the right way to return an object from a function? Car getCar(string
What is the right way to create custom pgsql types for django application so
What's the right way to control timeouts, from the client, when running against a
What's the right way in Drupal to create reports? I was hoping to use
What is the right way to stop an endless while-loop with a Term::Readline::readline ?
What's the right way to shut down a MediaController with an attached MediaPlayer ?
I'm curious as to what the right way to convert builtin types is in
G'Day Mates - What is the right way (excluding the argument of whether it
I am trying to find the right way to write code regarding checking for

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.