aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads: Difference in calling run() and start() 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: Difference in calling run() and start()" Watch "Threads: Difference in calling run() and start()" New topic
Author

Threads: Difference in calling run() and start()

C Halbe
Greenhorn

Joined: Jul 18, 2008
Posts: 20
I know that once a thread gets an ID it will not change until the thread is dead. But why does the ID change when we run the below code with start() and it does not change when we call the run() directly?



Please help me understand.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4461
    
    8

Because when you call run() directly you aren't creating a new thread, you're just calling the run() method in the current thread. It's just a normal method, there's nothing stopping you calling it like any other method. Whereas calling start() will create a new thread and execute run() in that.
C Halbe
Greenhorn

Joined: Jul 18, 2008
Posts: 20
Got it! Thanks.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4461
    
    8

No problem!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads: Difference in calling run() and start()