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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:58:03+00:00 2026-06-18T12:58:03+00:00

Suppose during my running I would like to shutdown a single thread gracefully! I

  • 0

Suppose during my running I would like to shutdown a single thread gracefully!

I don’t want to use Thread.stop() nor Thread.destroy() due to their unsafe behavior.

Note: I’m familiar with using ExecutorService.shutdown() option.
But I would like to know the other way to implement.

  • 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-18T12:58:04+00:00Added an answer on June 18, 2026 at 12:58 pm

    The standard way to stop a thread is to call thread.interrupt();. To make it work, you need to make sure you thread responds to interruption, for example:

    Thread t = new Thread(new Runnable() { public void run {
        while(!Thread.currentThread().isInterrupted()) {
            //your code here
        }
    }});
    t.start();
    t.interrupt();
    

    This only works if the condition is checked regularly. Note that you can delegate the interruption mechanism to interruptible methods (typically I/O, blocking queues, sleep/wait provide methods that can block until they are interrupted).

    Note: In this example, you can also use:

        while(!interrupted()) {
            //your code here
        }
    

    interrupted() does the same thing as Thread.currentThread().isInterrupted() except that the interrupted flag is reset. Since it is your thread, it does not matter.

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

Sidebar

Related Questions

Suppose I have several 200mb+ files that I want to grep through. How would
I would like to create a static menu. I mean during compilation I'll know
Suppose we have the name written in any none-latin letters - languages, like Arabic,
what will happen if connection lost during transactional replication? suppose db1 and db2 are
How do I change any CSS properties during runtime? Suppose I have: #mycss {
suppose I have an object like this: class Spline { public: Spline(std::size_t const dim);
Suppose we have many user processes running on Linux. Each process has many threads
In hadoop, suppose the number of nodes is fixed (no server crash during the
Suppose a shutdownHook as : class ShutdownHolder extends Thread { public void run() {
suppose you save data into a dynamic hidden field ,which is created dynamically during

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.