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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:56:09+00:00 2026-05-26T11:56:09+00:00

I know that Thread.stop() and other functions are deprecated, and I want to stop

  • 0

I know that Thread.stop() and other functions are deprecated, and I want to stop a thread from running if a certain condition is met. Here is a simplified version of what I’m doing now:

public class SomeThread extends Thread
{
    private static boolean running = true;

    public static void shutdown()
    {
        running = false;
    }

    public void run()
    {
        while( running )
        {
            // do something cool
        }

        return; // <- this is what I'm wondering about
    }
}

When another class calls SomeThread’s shutdown() method, the while loop exits, and then the run() method returns. Is this safe?

The main reason I’m using a while loop instead of just letting run() do the work is because there are a few things I only want to do once (before the while loop), and I’m really only using the thread for concurrency. I’m sure this is a bastardization of what Threads were meant for, but I’m mainly just wondering about the return statement.

  • 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-26T11:56:10+00:00Added an answer on May 26, 2026 at 11:56 am

    The return is fine, the rest of your code is iffy.

    The running member should either be volatile, or you need some synchronization around the reads and writes to that variable.

    (Having shutdown and running as statics is unusual.)

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

Sidebar

Related Questions

I want to know that is boost::asio::deadline_timer thread safe? Can somebody answer me?
I know that the stop method has been deprecated and I am using destroy
I have a thread that running into an activity. I don't want that the
I know that there are some threads have a similar issue with this thread.
I already know that most implementations use a single thread, but is there anything
Firstly I know that there are many question and solutions to correct thread marshalling
I know the thread which says that rebase is for small changes of teamMates,
I know that many threads has been created here & on the internet about
I have a multi-thread C# application that uses some recursive functions in a dll.
How is the implementation of threads done in a system? I know that child

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.