Topic: 求助,scjp中的一道题

  Print this page

1.求助,scjp中的一道题 Copy to clipboard
Posted by: itview
Posted on: 2004-02-26 21:39

Given:

1. public class SyncTest {
2. private int x;
3. private int y;
4. private synchronized void setX (int i) {x=1;}
5. private synchronized void setY (int i) {y=1;}
6. public void setXY(int i){setXLight Bulb; setYLight Bulb;}
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.

请高手告诉我答案和解释,多谢了!

2.Re:求助,scjp中的一道题 [Re: itview] Copy to clipboard
Posted by: dingligang
Posted on: 2004-02-27 14:30

第4行的:x=1; 应该是 x=i; 吧?
第5行的:y=1;也应该是 y=i; 吧?

看些同步方面的知识点,选B吧?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923