• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

start() in Thread class

 
akshitha Akki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens at the backend when the start() function is called in the multithreaded programming?
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It calls the run method Runnable interface, which gets placed in a different method stack.
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most importantly, start method actually creates a real, machine-level thread before making a call to run method.
Also, this new thread has its own call stack.

This doesn't happen when we directly invoke run method. A separate thread is not created and that method is invoked in same original thread, just like any other method.

I hope this helps.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you write Thread t = new Thread(myRunnable); // myRunnable is a reference to Runnable object

the above statement does not create any Thread. so what does it do ? it simply create a Thread object. but as Ayonkar said, it does not create THREAD OF EXECUTION. however when you call t.start(), then actually a new THREAD OF EXECUTION spawns and invoke the run() method of the runnable in a NEW thread. keep in mind the context in which we speak of Thread. let me repeat , Thread t = new Thread(myRunnable) only creates Thread object. when you call run() method the Thread starts running and is in a running state(depending upon the Thread Scheduler).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic