• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Issue with synchronization

 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


first of all, is there any chance that this program will ouput the line "A Hello!"? I always got "B Hello!".
if it'll never print "A Hello!", could anybody explain why?
thanks
 
author
Posts: 23959
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

David Spades wrote:
first of all, is there any chance that this program will ouput the line "A Hello!"? I always got "B Hello!".
if it'll never print "A Hello!", could anybody explain why?



Scheduling of threads is not defined by the JVM specification. This is mainly to allow the native threading system to schedule threads as they like. This is also true with the use of condition variables (ie. wait/notify).

So, to answer your question... The behavior is not defined.

Henry
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have just added a while loop and see that both B Hello and A Hello do appear but not in any deterministic order.



This should be normal.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will be good to know what are you trying to prove/test here.
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Spades wrote:
first of all, is there any chance that this program will ouput the line "A Hello!"? I always got "B Hello!".
if it'll never print "A Hello!", could anybody explain why?
thanks



David ,
When I'm running your code am getting below output :

List is empty...
List is empty...
Opening...
Interrupted Exception!
New Element:'Hello!'
notifyAll called!
Closing...
Interrupted Exception!


Your code it is quite self explanatory ..

If I modify the code like this


then I get :

List is empty...
Interrupted Exception!
Opening...
New Element:'Hello!'
notifyAll called!
Closing...
A Hello!

Thanks ,
Satya
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic