Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why main thread should complete before other threads  RSS feed

 
Vasantha Prabha
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Basic Question why main thread should be completed before the
all the thread in java.
Regards,
Sangeetha
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just a matter of program design. I have a little program that spins off a number of threads to do some work. I read the starting point for each thread from a file and rewrite the file to record how much got done. I stop all those worker threads before the main thread rewrites the file and exits the program.
There are programs that can let the main thread end while other threads go on. Have you done any Swing programming? You might write a little main() routine that opens a frame. Opening the frame gets the Swing thread going, and the Swing thread goes until you shut down the program, even though the main ended almost immediately.
Do those examples help?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!