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

Thread Question

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.public class SyncTest {
2.private int x;
3.private int y;
4.public synchronized void setX (int i) ( x=1; )
5.public synchronized void setY (int i) ( y=1; )
6.public synchronized void setXY(int 1)( set X(i); setY(i); )
7.public synchronized Boolean check() ( return x !=y; )
8.)
Under which conditions will check () return true when called from a different class?
A.check() can never return true
B.check() can return true when setXY is called by multiple threads
C.check() can return true when multiple threads call setX and setY separately.
D.Check() can only return true if SyncTest is changed to allow x and y to be set separately.

The given answer is B. But I am not sure that's the right answer. And I don't know what is the point of this question. What does it try to test?
Thank you in advance.

(Marilyn disabled smilies)
[ May 05, 2002: Message edited by: Marilyn deQueiroz ]
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answers are B and C.
Give a search to get good explanations. The same question had been discussed earlier in this forum...
 
Climb the rope! CLIMB THE ROPE! You too tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic