wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads - Run and Start methods. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads - Run and Start methods." Watch "Threads - Run and Start methods." New topic

Threads - Run and Start methods.

vikram Kesav
Ranch Hand

Joined: Jul 11, 2008
Posts: 69
i read from K&B is 'start' method of thread creates new stack for the thread.

i would like to know what is the meaning of stack for thread.
How this stack works....???where it resides in the memory...???
how run method get reference of new stack..???

Ankit Garg

Joined: Aug 03, 2008
Posts: 9291

Kesav every thread has a method call stack of it's own. When you call start on a thread object, then a new thread is created and the run method is called on the new thread. The run method doesn't receive the stack. It is used by the thread to keep a list of pending method calls.

Suppose in a thread run is called then the method stack of the thread contains

Now if run calls another method func, then the stack of the thread becomes

Now if func calls a method myMethod, then the stack of the thread becomes

Now when the myMethod returns, the stack of the thread becomes

and when the func method returns, the stack of the thread becomes

And when the run method ends, then there is no pending method in the stack of the thread so the thread is ended.

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Prav sharma
Ranch Hand

Joined: Feb 07, 2005
Posts: 102
Nice pictorial explanation !!!
I agree. Here's the link: http://aspose.com/file-tools
subject: Threads - Run and Start methods.
Similar Threads
thread EXAM WATCH from K&B
Doubt about threads
difference between start() and run() of a thread instance
q on threads
Is there any method which creates..........?