File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Question

 
Jo Liang
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • 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...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic