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 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

Hi: I have a multi thread Java program. There are many singletons. I am
Hi: I have a multi thread Java application. There are many temporary objects. -XX:MaxTenuringThreshold=1
I have a cache I want to periodically check and prune. In Java, I'd
Hi i am getting the following exception while fetching the image from server. I
The problem: I can't get my java app to run after compiling. My guess
First I did this - String str = {\hits\:[{\links_count\:6,\forum_count\:11}],\totalHitCount\:1}; Assert.assertTrue(str.matches({\hits\:[{\links_count\:[0-9]{1,},\forum_count \:11}],\totalHitCount\:[0-9]{1,}}), Partnership message does
I start one thread to download contents from the internet, at one time, the
Assuming that Runtime.getRuntime().addShutdownHook(new Thread() has been set up correctly, how can the ShutdownHook thread
I'd like to programmatically limit an upload or download operation in Java. I would
I've got a drupal site that gets low traffic, but has tons of new

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.