• 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

Thread.start()....

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To run a thread, we need to call start(). So run() method gets executed. But how it is accomplished?

I dont see any run() called from start() when i checked Thread.start() method implementation.

Actually, what happens when Thread.start() is executed by JVM, behind the scenes?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guess what interface the Thread class is implementing. If you look at the start() method in the API, this is all explained.
 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thread is implementing Runnable interface. But i dont understand your point here.

I did check start() API of Thread class and dont see any run() getting called in it. It calls some native methods only.

Can please explain, what are you trying to say?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't look well enough

API wrote:
start()
Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vinney Shanmugam wrote:To run a thread, we need to call start(). So run() method gets executed. But how it is accomplished?

I dont see any run() called from start() when i checked Thread.start() method implementation.


If you would have followed the called methods from Thread.start() you would have found a call to start0() which is a native method. The actual launching of the thread and calling of run() is done in native code.
 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did see the comment " * Causes this thread to begin execution; the Java Virtual Machine
* calls the <code>run</code> method of this thread.
*

"

I too guessed that run() should be called from native. But can't let my hypothesis remains, without confirmation. Thanks for the reply.

 
Can you smell this for me? I think this tiny ad smells like blueberry pie!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic