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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:48:20+00:00 2026-06-12T11:48:20+00:00

I initialize new Thread in service but when i start service the new one

  • 0

I initialize new Thread in service but when i start service the new one is made and it make my app crash beacause I use camera in it.
How to make that it will be ony one instance of that Thread?

When Thread is closing? If I close service where I made it, it will be also closed?

  • 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-12T11:48:21+00:00Added an answer on June 12, 2026 at 11:48 am

    you could use a lock or a static variable:

    private static boolean isThreadRunning;
    

    and then in your service:

    if(isThreadRunning)
       return;
    
    Thread t=new Thread(new Runnable(){
    
    protected void run(){
       isThreadRunning=true;
       while(yourcondition){
         //your thread code...
       }
       isThreadRunning=false;
       //if you want to start another thread after this one is ended, you should post a message to a handler here and it should start another thread like this
    }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found out this morning that proc.new works in a class initialize method, but
I have a thread that get I initialize like this: Utility.Log(1); myThread = new
Say I have the following Backbone Router: class App.Routers.ThingsRouter extends Backbone.Router initialize: -> new
PhysicsThread.java starts a new thread. The run method executes the initialize method. This method
I have service with thread, From activity I am calling start service(from Activity::onDestroy()) and
I have a windows Service that start some tasks based on a configuration. Each
Objective Initialize a new addition problem for users to solve when they visit /task
I'm doing an INSERT INTO query in order to initialize a new table. The
Can I initialize an IOLoop.instance and than fork new processes, which uses IOLoop.instance()? Something
When i try to initialize velocity engine using VelocityEngine engine = new VelocityEngine(); engine.init();

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.