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

Main method doubt

 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is the main method the primary thread that springs in to action when we type in java filename in the command prompt.
Is it a thread that does not to be invoked in the conventional manner.
As in Mythread t1=new Mythread();

The thread that does not need to be elaborated on?

Also, I was curious; what convention does one follow to specify the prioity level of a thread in general.
What exactly does 5 mean, "the most important thread" or " the least important one".
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you run Java class, the JVM looks for the "main()" method and creates a thread for it (called main thread). It assign a stack and all the consequent threds ar children of this main thread call stack.

About Thread Priority
Java Thread Priority

 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell me one thing then,
the JVM "makes" a "main thread" out of the main method written by us?
Is it so?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varun Goenka wrote:
the JVM "makes" a "main thread" out of the main method written by us?

Yes, we need someone to start, and that someone is JVM which creates a non demon main thread for you so that you can execute your code, by executing "main()" method. Now, How JVM do that, is beyond my knowledge, I don't have a code of JVM .exe file
 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So we can like,use the sleep method, pointlessly, just for fun even though we arent using any thread.
Make things work slowly to "corroborate" the fact that java is slow?
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look, Thread#sleep() and Why Java is Slow is two different questions, they are not related to each other. You can transfer running thread to sleep state by using sleep() method, and the same thing is true about main thread and that' doesn't make Java slow

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic