,我讀了1.5,我們可以使用枚舉爲單同步上枚舉監測
public enum Singleton {
INSTANCE;
//Singleton method
public void someMethod() {...}
}
Singleton.INSTANCE.someMethod();
這是否意味着在枚舉類型的每個條目是一個實例本身? 如果我使用類定義枚舉類型,我可以在枚舉類型的每個條目上使用塊同步嗎?
class smokers extends Thread{
public enum restype{
TOBACCO,MATCH,PAPER
}
public void run(){
if(xxxx){
synchronized(restype.PAPER){
....
}
}
else
{
synchronized(restype.MATCH){
....
}
}
}
這個有效的代碼是?
然後,他應該stil同步該方法,例如:'PAPER {0} {0} {} }' – Chirlo