Strange Eventually Translation

今天在看SCJP Java 6專業認證手冊(附光碟)這本書的第9章執行緒的自我評量有一題:

Given:
public class TwoThreads {
static Thread laurel, hardy;
public static void main(String[] args) {
laurel = new Thread() {
public void run() {
System.out.println("A");
try {
hardy.sleep(1000);
} catch (Exception e) {
System.out.println("B");
}
System.out.println("C");
}
};
hardy = new Thread() {
public void run() {
System.out.println("D");
try {
laurel.wait();
} catch (Exception e) {
System.out.println("E");
}
System.out.println("F");

}
};
laurel.start();
hardy.start();
}
}
Which letters will eventually appear somewhere in the output? (Choose all that apply.)
A. A
B. B
C. C
D. D
E. E
F. F
G. The answer cannot be reliably determined
H. The code does not compile

中文的題意是這樣的:

哪一個字母最後會出現在結果當中?(選擇所有適合的。)

答案是這樣的:

A, C, D, E, and F are correct. This may look like laurel and hardy are battling to cause
the other to sleep() or wait()—but that’s not the case. Since sleep() is a static
method, it affects the current thread, which is laurel (even though the method is invoked
using a reference to hardy). That’s misleading but perfectly legal, and the Thread laurel
is able to sleep with no exception, printing A and C (after at least a 1-second delay). Meanwhile
hardy tries to call laurel.wait()—but hardy has not synchronized on laurel,
so calling laurel.wait() immediately causes an IllegalMonitorStateException, and
so hardy prints D, E, and F. Although the order of the output is somewhat indeterminate
(we have no way of knowing whether A is printed before D, for example) it is guaranteed
that A, C, D, E, and F will all be printed in some order, eventually—so G is incorrect.
B, G, and H are incorrect based on the above. (Objective 4.4)

A、C、D、E、F都對,但是ㄚ琪從英文的eventually來看是『at the end of a period of time or a series of events 最後;終於』

所以直覺地看是哪一個字母會是結果最後的?不知這樣解讀是否正確?但是這樣子解讀的話,ㄚ琪很疑惑,A或D有可能是最後的嗎?好像不可能?

不知哪位大德可以協助解讀的!

感謝你看到這裡,很快就可以離開了,但最好的獎勵行動就是按一下幫我分享或留言,感恩喔~

點我分享到Facebook

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *