aspose file tools *
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on exercise about Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on exercise about Thread" Watch "Question on exercise about Thread" New topic
Author

Question on exercise about Thread

brian
Greenhorn

Joined: Jan 23, 2003
Posts: 7
Do you know the answer

Under which conditions will check() return when called from a different class. Choose one

A. check() can never return true
B. check() can return true when set XY is called by multiple threads
C. check() can true when multiple threads call set X and set Y separately
D. check() can only return true if synchTest is changed to allow x and y to be set separately
[ January 25, 2003: Message edited by: Jessica Sant ]
hiti hitox
Greenhorn

Joined: Jan 23, 2003
Posts: 3
A) isnt right, because of B)
Answer B) is right.
A call to setXY makes calls to the synchronized methods setX / setY.
But the method setXY isn't synchronized. So it can be called by multible threads.
Ex:
When thread1 call setXY(8), method setX(8) called.
Here comes thread2 with call setXY(9).
Thread1 leaves setX(8) and call setY(8).
Now Thread2 can enter setX(9)
Thread1 call check() and ups! x==9, y==8!
C) Can't happen, cause setX/setY are private
D) completely beside it
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
brian,
Welcome to Javaranch, a friendly place for Java greenhorns
We ain't got many rules 'round these parts, but we do got one. Please change your displayed name to comply with the JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on exercise about Thread