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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:25:51+00:00 2026-06-06T18:25:51+00:00

I have a class XYZ which extends Thread and it is also a singleton

  • 0

I have a class XYZ which extends Thread and it is also a singleton (Yes. My application needs that).

In the run method, I have something like this:

public void run() {
    service.start();
}

The time it takes for service.start() is huge.
Also, my application will not always need the thread to be run but can’t decide in advance so while launching the application I am starting this thread.

Now, when application doesn’t need the thread, it gets completed very quickly and all I need to do is wait for thread to die.

I tried to use stop() method but came to know that it is deprecated.

  • 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-06T18:25:52+00:00Added an answer on June 6, 2026 at 6:25 pm

    stop has been deprecated a long time ago and should not be used. Thread termination is a cooperative process in Java (i.e. the interrupted code must do something when asked to stop, not the interrupting code) – one way is to call thread.interrupt() on the thread you need to interrupt.

    You then need to catch the generated interrupted exception in the running thread or check the interrupted status regularly. Once the running thread detects that is should stop what it’s doing, you can then run any cleanup tasks as required and exit whatever you were doing.

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

Sidebar

Related Questions

I have a line of code which is... <div class=x> xyz </div> I want
I have a class called XYZ inheriting from NSObject and an array which contains
We have a requirement in application that on clicking on all images which do
I have a class which extends AsyncTask public class SendJSONArray2Server extends AsyncTask<String, Void, HttpResponse>
I have a class which extends the TextEditor for creating an editor view. I
Suppose I have three projects in my sln. (1) xyz.a{Class Lib}{no reference added} (2)
I have class A, which exposes an event. an object of class B subscribed
I have class that represents users. Users are divided into two groups with different
I have class A {} class B : A {} I also have a
I have class A and classes B and C. class B runs one thread

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.