• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread.start()....

 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • 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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic