Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How is main a thread

 
Harvinder Singh
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Java'sSocialWorkers:-),
A class that has a main() method may or may not implement the Runnable Interface or extend the Thread class then how the main() is called the first
non-daemon thread that JMV runs when the class is loaded.further the JVM only calls the run() method of the class to which the thread belongs.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thread that executes an application has been named "main" because it executes the code in the main method. The class holding the main method is not otherwise related to this thread.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is main a thread?
Even if the virtual machine is not actually coded this way, it seems like a reasonable way the virtual machine could start the main thread:

The idea here is that the virtual machine (theoretically) creates a Runnable object that invokes the static method main. Then it creates a Thread object and passes that Runnable object as the thread target.
Notice how this can explain why we can throw checked exceptions from main().
Why am I spreading such myths? Until I find out how it really works, this is how I explain to myself how the main thread is just like any other thread. But I defer to Jose, our virtual machine expert.
[ October 06, 2003: Message edited by: Marlene Miller ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic