• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 22649
126
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.

 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic