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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:24:49+00:00 2026-06-15T10:24:49+00:00

I saw this question: how to run one thread after complete another thread ,

  • 0

I saw this question: how to run one thread after complete another thread , but the answer to it is not appropriate for me.

I have such kind of java code for Android:

public void startTask(Runnable r)
    {
        running = true;
        Log.i(tag, "-----------start.Runnable-----------");

        Thread first = new Thread(r);
        first.start();

        Thread second = new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                running = false;
            }
        });
}

first Thread takes as param Runnable object with some hard operation which I am processing in background service. So, when I call method: startTask() I set running = true; to prevent double executing tasks. But, also, I need right after completeness of first thread start second thread to set running = false; to enable other operations to execute.

How can I wait completeness of first thread by second not to freeze main thread?? Thanks!

  • 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-15T10:24:49+00:00Added an answer on June 15, 2026 at 10:24 am

    Try this:

    final Thread first = new Thread(r);
    first.start();
    
    Thread second = new Thread(new Runnable() {
    
        @Override
        public void run() {
            first.join();
            // TODO Auto-generated method stub
            running = false;
        }
    });
    second.start();
    

    I changed:

    • add final keyworrd for ‘first’
    • wait finish of first thread by #join at begin of second thread.
    • start sencond thread soon.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading this question , i saw the answer by Naveen containing a link
I saw this answer to a similar question , but it always scares me
Note: I already saw this and it doesn't answer the question. I have a
I just saw this question and one of the answers looks really appealing to
So I saw this post which helped answer part of my question however now
I just saw this dating site on builtwithbootstrap and have a question about table
I know this may seem like a math question but i just saw this
I also posted this question on the Google Group https://groups.google.com/forum/?fromgroups#!topic/d3-js/DYiVeC544ws , but saw that
This is a complete noob question, but I gotta ask it anyway I started
I saw this relevant question but my situation is different so asking this again.

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.