Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Why first output is second output

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
im reading a tutorial and tried to run Safelock example shown in HERE
When i run this program the first output lines are :

Gaston: Alphonse has bowed back to me!
Gaston: Alphonse has bowed to me!

And i cant undestand how the first line can be "Gaston: Alphonse has bowed back to me", if the first output statement in method "bow" is "...bowed to me..." and both bowee and bower objects are locked for certain thread. so i thought if one thread started some method it has to do all statements in the order they are written and others threads cannot interleave because of locking both objects. so in my opinion the first lines of the output shoud be :

Gaston: Alphonse has bowed to me!
Gaston: Alphonse has bowed back to me!

or the same but with different names(first output should be" has bowed to me")

tell me if i understand the flow incorectly. it would be greate if you could explain the flow of execution, which leads to such situation(first output sentence is "bowed back to me")

p.s. more often the output is the same i expected. but sometimes i get result i can't understand.


thanks and sorry for my language mistakes
 
Jonas Dimsa
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
srr for mistake, i expected the first lines of output shoud be:

Gaston: Alphonse has bowed to me!
Alphonse : Gaston has bowed back to me!

i mixed the order of the names in second line
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It certainly works that way for me; perhaps you, as a lucky Windows user, are stuck with a terminal that's not quite sure of its size, and is cutting off the first line? You might try running it and capturing the output in a file, then looking at the file in an editor:

java Safelock > output
 
Jonas Dimsa
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you're absolutely right. Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic