This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

start() in Thread class  RSS feed

 
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?
 
Rancher
Posts: 1878
15
Android Eclipse IDE 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.
 
Bartender
Posts: 1558
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.
 
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).
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!