• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Doubt in Thread output

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23923
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23923
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see..thanks once again for quick reply.

Regards,
Tom
 
reply
    Bookmark Topic Watch Topic
  • New Topic