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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:44:37+00:00 2026-05-31T01:44:37+00:00

will main thread exit before child threads complete execution? i read in 2 articles

  • 0

will main thread exit before child threads complete execution?

i read in 2 articles

http://www.cs.mtu.edu/~shene/NSF-3/e-Book/FUNDAMENTALS/thread-management.html

in the above article, In “Thread Termination” para, it states in Red ” if the parent thread terminates, all of its child threads terminate as well.”

http://www.roseindia.net/java/thread/overview-of-thread.shtml

in the above article, the last line in that page states “The main() method execution can finish, but the program will keep running until the all threads have complete its execution.”.

i fee they are contradictory. if i am wrong, Please experts correct me.

In my program, a program with Main method calls the constructor of 2 threads . in the constructor of the respective threads, i am having the start() method .

     TestA  A = new TestA("TestA");
     TestB  B = new TestB("TestB");

     public TestA(String name) {
    System.out.println(name);
    t = new Thread(this);
    t.start();
}

i would like to know what happens, main thread terminates before child threads complete execution? if so, will the child threads anyway, continue their execution??

i tried running the program, some times all the child threads are getting executed complete even if the main thread exits.
In the 2 threads , i am processing some files. in testA thread A alone, 1 file alone is not getting processed some times. but many times, all the files are getting processed and i do not have any issues.

  • 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-31T01:44:38+00:00Added an answer on May 31, 2026 at 1:44 am

    Java makes a distinction between a user thread and another type of thread known as a daemon thread. The difference between these two types of threads is that if the JVM determines that the only threads running in an application are daemon threads (i.e., there are no user threads), the Java runtime closes down the application. On the other hand, if at least one user thread is alive, the Java runtime won’t terminate your application.

    When your main() method initially receives control from the Java runtime, it executes in the context of a user thread. As long as the main-method thread or any other user thread remains alive, your application will continue to execute.

    In your case, the threads are user threads and hence are allowed to complete before the main thread exits.

    i am processing some files. in testA thread A alone, 1 file alone is
    not getting processed some times. but many times

    The reason for the above is could be something else than thread exits. It could be file locks, synchronization issue etc.

    Thread (Java SE 10 & JDK 10):

    When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class). The Java Virtual Machine continues to execute threads until either of the following occurs:

    • The exit method of class Runtime has been called and the security manager has permitted the exit operation to take place.
    • All threads that are not daemon threads have died, either by returning from the call to the run method or by throwing an exception that propagates beyond the run method.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like in the above graph,all other threads will automatically exit once the main thread
Today I ran against the fact, that sys.exit() called from a child-thread does not
I have a system with multiple threads running - my main-thread just checks if
I'm trying to do a rather complicated SELECT computation that I will generalize: Main
You will notice the :hover CSS for the links in the main nav area
I have my main application ,from my main application I will be calling another
Presently, we've got several main projects each in their own repository. We will have
Will I have to pay again? I have about 9 months left before renewal
Before you say its a duplicate question, please let me explain (as I've read
In my main thread I have a while(listening) loop which calls accept() on my

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.