This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes start() in Thread class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "start() in Thread class" Watch "start() in Thread class" New topic
Author

start() in Thread class

akshitha Akki
Greenhorn

Joined: Aug 03, 2012
Posts: 24
What happens at the backend when the start() function is called in the multithreaded programming?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

It calls the run method Runnable interface, which gets placed in a different method stack.


Swastik
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1502
    
    5

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.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: start() in Thread class
 
Similar Threads
SCWCD Internal Fourm in Java Ranch
Sieve of Eratosthenes
WA #1.....word association
WA #2 ..... word association
jsf & strats