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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:01:41+00:00 2026-05-21T19:01:41+00:00

The Java thread join() method confuses me a bit. I have following example class

  • 0

The Java thread join() method confuses me a bit. I have following example

class MyThread extends Thread {
    private String name;
    private int sleepTime;
    private Thread waitsFor;

    MyThread(String name, int stime, Thread wa) { … }

    public void run() {
        System.out.print("["+name+" ");

        try { Thread.sleep(sleepTime); }
        catch(InterruptedException ie) { }

        System.out.print(name+"? ");

        if (!(waitsFor == null))
        try { waitsFor.join(); }
        catch(InterruptedException ie) { }

        System.out.print(name+"] ");

And

public class JoinTest2 {
    public static void main (String [] args) {
        Thread t1 = new MyThread("1",1000,null);
        Thread t2 = new MyThread("2",4000,t1);
        Thread t3 = new MyThread("3",600,t2);
        Thread t4 = new MyThread("4",500,t3);
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}

In which order are the threads terminated?

  • 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-21T19:01:42+00:00Added an answer on May 21, 2026 at 7:01 pm

    What actually confuses you about Thread.join()? You haven’t mentioned anything specific.

    Given that Thread.join() (as the documentation states), Waits for this thread to die, then t4 will wait for t3 to complete, which will wait for t2 to complete, which will wait for t1 to complete.

    Therefore t1 will complete first, followed by t2, t3, and t4.

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

Sidebar

Related Questions

Does anybody know why the method join() member of a java.lang.Thread was named like
The following code leads to java.lang.IllegalThreadStateException: Thread already started when I called start() method
Say I have the following code: import java.lang.InterruptedException; import javax.swing.SwingWorker; public class Test {
Is the standard Java 1.6 javax.xml.parsers.DocumentBuilder class thread safe? Is it safe to call
I have a layered application in Java which has a multi thread data access
Despite the upcoming java 7 standard fork/join framework, I am building some helper method
i have this little class to make a multiple replace on a string: import
When would you call Java's thread.run() instead of thread.start() ?
I am coming up with a design for a task based multi-thread java 1.5
Java has the thread dump which is triggered by a signal 3 sent to

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.