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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

It is too much ....

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


Every body knows that , when any thread calls yield() method , it has to go in runnable state .

In above example , it is sure that output will be false every time ( I can bat for this ) ...

But In this case also , is it right to choose No guarantee ... It is too much ...

Thanks .
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
For this case, I'll still choose "No guarantee". It's possible that the main thread yields and is then reselected by the scheduler especially for threads with same priority (well, that's what K&B book says on pg 513 ).
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Running this program in the BlueJ IDE gives the result true
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Come-on Barry ,
It can't be dependent on IDE ...
It may be because of your JVM .
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Calling yield() puts the thread into Ready state, but some scheduler implementations will ignore the call if it determines that it will only put the thread back into Running state immediately after.

The output of your test case is indeterminate.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Originally posted by rathi ji:
Come-on Barry ,
It can't be dependent on IDE ...
It may be because of your JVM .



I tried the same program in Eclipse and BlueJ with the same jdk and jre and found false and true output respectively. It can't be dependent on IDE as rathi said then why am i getting different output???
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
What do you mean by same JVM and JRE? You just mean the same version, e.g. 1.3.1? If so, there might be problems, as different JVM might give different results.

As you might know, the behavior of JVM in WSAD/WAS is different from the one in SunONE, say, even both declare that they are J2SE 1.3.1.

Nick
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Like already stated, there are no guarantees so yield might not have the effect of getting the other thread to run at all.
This is not IDE dependent, not JVM dependent, it's pure chance.
One run might produce false, another true. Maybe you get true a thousand times and then false just once, there's just no telling.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Rathi, why did you post this twice? You know our rules about duplicate posting.

I am going to close this thread, since the other one has my really funny response of "42".

Mark
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
    Bookmark Topic Watch Topic
  • New Topic