• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread  RSS feed

 
badrinarayanan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginner and this might be an absurd question......and so friends kindly bear with me..requesting ur help in this case

In a class it is said that main() is a thread...why dont we implement the Runnable() interface or extend the Thread class for it?
 
shreehari Gopalakrishnan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Badri

It is surely not an absurd question as u mentioned

When ever we create a java program one thread called main is created
but it is not in your control. it is in full control with JVM.
The thread "Main" runs in JVM.so no need to extend the Thread class or implement Runnable

If U are creating u'r own thread then u need to extend Thread or implement Runnable.
If u do so thread will be on u'r control

we can say that the thread main is not in the control of the programmer
It is with the control of JVM

Hope U Got it!
 
badrinarayanan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi srihari

Thanks for ur answer and one more question...is it possible to get any information about the main thread
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can get reference to the main thread by calling Thread.currentThread().
Now you can work with it as with any other therad.
For example you can dumpStack().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!