• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How is main a thread

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic