File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes star() and run() in Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "star() and run() in Thread" Watch "star() and run() in Thread" New topic

star() and run() in Thread

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 386
When a Thread class is extended to create a thread, run() of Thread class is overridden. Does it mean that I don't need to use start() to start the thread and I can directly execute run() to start new thread ? OR do I still need to execute start() of Thread class, which in turn will execute run() of Thread class ?

Does it mean that no matter what, to start second stack for thread, its required to execute start(). If I execute run() without start(), then this run() will go on the same stack where main() is executed ?

Is start() only way to start a new stack or is there any other way also ?

Khuzema Dharwala
Ranch Hand

Joined: Apr 26, 2010
Posts: 49

call to start() is required to create a separate thread of execution irrespective of whether you are extending a Thread class or implementing Runnable interface

you can test this scenario by calling static activeCount() method of Thread class which will return active threads in the current thread's thread group.


I agree. Here's the link:
subject: star() and run() in Thread
It's not a secret anymore!