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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:09:50+00:00 2026-05-23T12:09:50+00:00

I am confused uisng joins method in Threads Could somebody please explain I have

  • 0

I am confused uisng joins method in Threads
Could somebody please explain
I have read that the Parent Thread would wait for its
child Thread , until the child completes its operation

I have a Parent Thread as shown :

public class join implements Runnable {

    public void run() {

        System.out.println("Hi");

    }

    public static void main(String[] args) throws Exception {
        join j1 = new join();
        Thread parent = new Thread(j1);

        child c = new child();

        Thread child = new Thread(c);

        parent.start();
        child.start();
        parent.join();

    }
}

Child Thread :

    public class child implements Runnable {


            public void run() {
                    try {
                        Thread.currentThread().sleep(100000);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                            System.out.println("i m child");

            }


}

Upon executing this , the output is

Hi

i m child

As per my understanding it should be in the reverse order

i m child

Hi

Please correct me if i am wrong

  • 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-23T12:09:50+00:00Added an answer on May 23, 2026 at 12:09 pm

    In your case you have three threads: main, parent and child. Main is the initial thread that is always created by the jvm to run your program. Parent and child are two threads that have been created in main. Your labeling of one thread as parent is a misnomer. It is the parent of no other threads. Rather it is the child of main. Join is intended so that one thread may wait for another to finish execution, before it continues.

    A hypothetical example might be between a waiter and a chef. That is, a waiter cannot serve food until the chef has cooked it. So the waiter must needs to wait for (join) the chef to finish before serving the food.

    public static void main(String[] args) {
    
        Thread child = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("child doing its work");
            }
        });
    
        child.start(); // start child thread
        child.join(); // wait for child to finish
    
        System.out.println("Now back in main. Child has finished its work");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that imports data read from text files from a directory
I'm a bit confused here. Microsoft as far as I can tell claims that
I'm a little confused about how the standard library will behave now that Python
Im getting very confused with indexes in MySQL. I have two tables: TableA1 and
I have read a lot of articles about whether we should have primary keys
I have written a table-valued UDF that starts by a CTE to return a
I am confused about how to set this up using Cake's conventions. I have
As we know that there are different types of JOINs in any RDBMS, for
I'm very confused in creating Tables in MySQL because I read some PHP tutorials
I am trying to understand joins and im a bit confused. I know how

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.