• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Thread output

 
Tom Ethens
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21429
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tom Ethens
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the clarification Henry.

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

Regards,
Tom
 
Henry Wong
author
Marshal
Pie
Posts: 21429
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see..thanks once again for quick reply.

Regards,
Tom
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic