SCJP題庫第226題

 
Which two statements are true? (Choose two.)
A. It is possible to synchronize static methods.
B. When a thread has yielded as a result of yield(), it releases its locks.
C. When a thread is sleeping as a result of sleep(), it releases its locks.
D. The Object.wait() method can be invoked only from a synchronized context.
E. The Thread.sleep() method can be invoked only from a synchronized context.
F. When the thread scheduler receives a notify() request, and notifies a thread, that thread immediately releases its lock.

Ans: AD

解說:

A. It is possible to synchronize static methods.
對靜態的方法同步是可能的。

B. When a thread has yielded as a result of yield(), it releases its locks.
當一個執行緒執行yield方法時,會釋放他的locks。
(執行yield不需要取得與釋放locks)

C. When a thread is sleeping as a result of sleep(), it releases its locks.
當一個執行緒執行sleep(),會釋放其locks…
(執行sleep不需要取得與釋放locks)

D. The Object.wait() method can be invoked only from a synchronized context.
一個物件的wait方法只能由同步的本文中被叫用。
E. The Thread.sleep() method can be invoked only from a synchronized context.
Thread.sleep()方法只能由同步的本文中被叫用。
(不必)

F. When the thread scheduler receives a notify() request, and notifies a thread, 
that thread immediately releases its lock.

當執行緒的排班器收到一個notify的通知,被通知的執行緒會立刻釋放其lock

(排班器是負責從runnable狀態中的執行緒找一個進入cpu,不會去處理在wait狀態中的執行緒)


Comments

Popular posts from this blog

Android-使用webview在V3版的Google地圖GPS定位