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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:30:13+00:00 2026-05-16T18:30:13+00:00

Please help me understand this program’s execution and what concepts apply here in the

  • 0

Please help me understand this program’s execution and what concepts apply here in the larger sense? An illustration which explains thread(s)/stack(s) creations and destruction would be helpful.

class Joining {

    static Thread createThread(final int i, final Thread t1) {
        Thread t2 = new Thread() {
            public void run() {
                System.out.println(i+1);
                try {
                    t1.join(); 
                } catch (InterruptedException ie) {
                }
                System.out.println(i+2);
            }
        };
        System.out.println(i+3);
        t2.start(); //1
        System.out.println(i+4);
        return t2;
    }
    public static void main(String[] args) {
        createThread(10, createThread(20, Thread.currentThread()));
    }
}
  • 1 1 Answer
  • 3 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-16T18:30:13+00:00Added an answer on May 16, 2026 at 6:30 pm
    1. The inner createThread call is called at the bottom from the main thread [M], with the arguments 20 and the current thread.
    2. This call prints 23.
    3. A new thread [A] is started (and will be returned) which prints 21, and waits for the main thread [M] to die (and will print 22 after it does).
    4. This call prints 24. It’s impossible to know if this will happen before the new thread [A] prints 21.
    5. This call returns the new thread [A], which is waiting for the main thread [M] to die.
    6. The new thread [A] is passed as the second argument to the createThread call with 10 as the first argument.
    7. This call prints 13.
    8. Another new thread [B] is started (and will be returned although nobody is catching this return) which prints 11, and waits for the first created thread [A] to die (and will print 12 after it does).
    9. This call prints 14. It’s impossible to know if this will happen before this second new thread [B] prints 11.
    10. This call returns the second new thread [B], which is waiting for the first created thread [A] to die, but nothing is being done with this return call.
    11. The main thread [M] runs out of things to do and dies.
    12. When the main thread [M] dies, the join() call on the first created thread [A] returns.
    13. The first created thread [A] prints 22.
    14. The first created thread [A] dies.
    15. When the first created thread [A] dies, the join() call on the second created thread [B] returns.
    16. The second created thread [B] prints 12.
    17. The second created thread [B] dies.
    18. The JVM shuts down, because all threads have died.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me understand this. I created a really simple program to try to
Please help me understand this recursive function... var stack = Array; function power(base, exponent){
I'm a noob; please help me understand this authentication config / bindings stuff that
Please help me. I can't understand why this function, that uses texture memory __global__
Please help me with this update query. I COMPLETELY understand how redundant this is
may someone please help me understand these lines of code in the program below
Please help me understand the following code snippet :- def any(l): whether any number
Please help me understand why add1() and add4() report errors and why add2() and
Please help me understand where I am going wrong so much so that I
the following code is not behaving like I would expect. Please help me understand

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.