wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Thread output 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 "Doubt in Thread output" Watch "Doubt in Thread output" New topic
Author

Doubt in Thread output

Tom Ethens
Greenhorn

Joined: Jun 10, 2008
Posts: 16
Hi all,

I have the following code


Now, the output that I get is
Overloading start method
Extending Thread Class

Run method overloaded--Passed String is Tom

Shouldn't I be getting the output as
Extending Thread Class
Overloading start method

Run method overloaded--Passed String is Tom

Why would the run() method with arguments take priority over the default run() method?

Regards,
Tom
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18875
    
  40

Why would the run() method with arguments take priority over the default run() method?


It doesn't. It is purely a detail of the JVM and OS, in its implementation of threads. On some JVM/OS combinations, one may always happen first. On other combos, the other may always happen. And with most combinations, you may see some runs of both.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Tom Ethens
Greenhorn

Joined: Jun 10, 2008
Posts: 16
Thanks for the clarification Henry.

So, does this mean that output related to any Thread question is never guaranteed?

Regards,
Tom
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18875
    
  40

Originally posted by Tom Ethens:
So, does this mean that output related to any Thread question is never guaranteed?

Regards,
Tom


No. That is an over generalization. Schedulling order is not guarranteed. But with the correct syncrhonization and / or time delays, an order can be show to always work.

While you have to be careful to assume an order, you also have to be careful to assume the opposite too -- as threads can get tricky, hence, some thread questions can get tricky...

Henry
Tom Ethens
Greenhorn

Joined: Jun 10, 2008
Posts: 16
I see..thanks once again for quick reply.

Regards,
Tom
 
GeeCON Prague 2014
 
subject: Doubt in Thread output