• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OCP- Thread Problem (K&B 7)

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear team,
I am studying for the OCP java Programmer and I am trying to do an test on the Study Guide but I can't understand its solution.

The test is the number 15, Chapter 13 (page 778) but I report it below:





The corretc answer says: the first output must be yo.
I really can't understand why.
Why can't the second Thread enter in the "while" and print "dude" before the first Thread (which changed the flag value)?

I am looking forward to hearing from you.

Thank you
Nicola
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That should always print "yo" if chat() method is synchronized. I agree that with this implementation, it can print dude as well at the first place.
 
reply
    Bookmark Topic Watch Topic
  • New Topic