2009年2月26日 星期四

第228題

Which three will compile and run without exception? (Choose three.)
A. private synchronized Object o;
B. void go(){
synchronized(){/* code here */}
C. public synchronized void go(){/* code here */}
D. private synchronized(this) void go(){/* code here */}
E. void go(){synchronized(Object.class){/* code here */}
F. void go(){Object o = new Object();
synchronized(o){/* code here */}
答案:CEF
參考:13-2 Java執行緒與Thread類別、13-3 Runnable介面、13-5 執行緒的互動處理

-------------------------------------

E. 使用synchronize 區塊 鎖定類別.
F. 使用synchronize 區塊 鎖定物件.

沒有留言:

張貼留言