wood burning stoves 2.0
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
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "start() in Thread class" Watch "start() in Thread class" New topic

start() in Thread class

akshitha Akki

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

Joined: Jan 08, 2009
Posts: 1584

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

Anayonkar Shivalkar

Joined: Dec 08, 2010
Posts: 1545

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.

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

Joined: Apr 04, 2012
Posts: 924

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
It's not a secret anymore!