Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main thread

 
Palash Kumar
Ranch Hand
Posts: 33
MyEclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if main method is executed in a seperate thread....
then does it contain run()

why main thread doesnot need to be started by calling start()
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if main method is executed in a seperate thread....


A separate thread from what?

main represents the entry point of a Stand Alone application, whereas run is really associated with a thread, and a thread is quite different from an entry point of a stand alone app.

I guess if you're wondering why, I guess they figured there's no need to.

-Cameron McKenzie
 
Palash Kumar
Ranch Hand
Posts: 33
MyEclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but main is also a thread
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I guess you could say a Servlet runs as a thread, as does an EJB, as does many other resources. But these resources are different enough from a thread that is spawned in a program that we treat them differently. I guess we don't need to start a thread when we call main for the same reason we don't when a servlet is invoked - it's because the runtime is just smart enough to do it for us.

-Cameron McKenzie
 
Andriy Pererva
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the main thread is usually started by JVM, after class-loader finished loading main class. You can try to change the signature of main method (or even delete it) and then run the class. You will get a NoSuchMethodError, because JVM didn't find an appropriate method signature.
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whenever you give a class file to the JVM.....it looks for the main method in other words main method is an entry for the JVM to your code and that entry is searched in the public class as its name is same as the file.

So when the JVM enters your code as new stack for that thing materializes....if you enter something there should be some room in there to run things that it has. So a new thread for it starts with its own stack memory.

Also in threads when you run the start() method the new stack for the thread materializes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic