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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:47:07+00:00 2026-06-18T12:47:07+00:00

I am seeing interesting behavior. I am running this code public class ThreadsTest {

  • 0

I am seeing interesting behavior. I am running this code

public class ThreadsTest {

    public static void main(String[] args) {
        Runnable mr = new MyRunnable();
        Thread t1 = new Thread(mr);
        Thread t2 = new Thread(mr);
        t1.setName("first");
        t2.setName("second");
        t1.start();
        t2.start();
        t1.run();
    } 
} 

class MyRunnable implements Runnable {
    public void run() {
    for (int i=0; i < 2; i++) {
        System.out.println("Running: " + Thread.currentThread().getName());
    }
    }
}

The output I get is:

Running: first
Running: first
Running: second
Running: second

I am expecting to see something similar to this:

Running: first
Running: first
Running: second
Running: second
Running: main
Running: main

Does anyone knows why I don’t see Running: main somewhere in my output. Thank you.

  • 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-18T12:47:08+00:00Added an answer on June 18, 2026 at 12:47 pm

    The explanation is a bit subtle.

    The default behaviour of the Thread.run() method is described as running the supplied Runnable if it exists, and doing nothing otherwise.

    The subtlety is that when a Thread exits, the exit() method “aggressively” nulls out reference fields to prevent storage leaks. (Here’s the source … line 720 onwards.) It appears that by the time that you called t1.run() in main, the thread had exited so the call was a no-op.

    Naturally, the output depends on whether or not the main thread gets to run again before the child thread exits … and that will depend on your platform; e.g. what the JVM and the OS-level thread scheduler do and how many cores are available.

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

Sidebar

Related Questions

I'm looking through some logs trying to explain some interesting behavior and I'm seeing
We are seeing 'interesting behavior with our SQL Sever Database. We have a merge
I'm seeing some interesting behavior in my program's link-local IPv6 multicast routines. It seems
I'm seeing an interesting behavior difference between my instance and my boss's instance of
I have been seeing this a lot lately and I am unable to find
I'm seeing my Ambient Data Framework code is entered on every http request, so
So I'm working on a fun little program and ran across this rather interesting
I was reading some c++ code, and i saw something interesting. The code was
We're seeing an interesting (though quite severe) issue with one of our application servers:
I am seeing an interesting result trying to use as a sys_guid() value in

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.