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

  • Home
  • SEARCH
  • 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 6664331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:35:55+00:00 2026-05-26T02:35:55+00:00

This is good example of stopping thread. How to stop a java thread gracefully?

  • 0

This is good example of stopping thread.
How to stop a java thread gracefully?
But when I try to check this example I received infinite loop.

This is my code:

public class Num {

    public void crash(ManualStopping t1) {
        t1.stopMe();
    }

    public static void main(String[] args) {

        Num num = new Num();
        ManualStopping t1 = new ManualStopping();
        t1.run();
        System.out.println("Main thread");
        num.crash(t1);
    }
}
class ManualStopping extends Thread {

    volatile boolean finished = false;
    public void stopMe() {
        finished = true;
    }
    public void run() {
        while (!finished) {
            System.out.println("I'm alive");
        }
    }
}
  • 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-05-26T02:35:56+00:00Added an answer on May 26, 2026 at 2:35 am

    I think you need to start your thread – not run it. By calling run, you are just making a normal method call, not running a separate thread.

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

Sidebar

Related Questions

for example this code var html = <p>This text is <a href=#> good</a></p>; var
This is working, but is this a good example of polymorphism? package mtm.test {
Want to check if this a good example for representing the abstract factory pattern.
i think this one is simple but i cant find a good example. What
This should be an easy one, but I can't find a good example anywhere.
A good example is the SO star on the left hand side of this
In this thread, we look at examples of good uses of goto in C
is this good code? can it be simplified somehow? SELECT u.id,u.title,u.title,u.first,u.last FROM (((tblusers u
I know there are emulators, but is this good enough? If someone is serious
I have to do something like this string = this is a good example

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.