線程同步隨記
1. wait:?? Causes current thread to wait until either another thread invokes the notify()
method or the notifyAll()
method for this object?? This method should only be called by a thread that is the owner of this object's monitor
?? 使當前線程放棄對象鎖(等待?),直到其它線程為該對象調用notify()或notifyAll().
?? 這個方法只能被擁有對象鎖(監聽器?)的線程執行。
??
??
2. notify,notifyAll
?? Wakes up a or all threads that are waiting on this object's monitor.
??
?? 喚醒正在等待指定對象的鎖的一個或所有線程。
-- 這樣翻譯也不知是否準確,括號內是按直譯過來的意思。
3. 四種方式?
?? 1.static synchronized method(){}
?? 2.sychronized(Class)
?? 3.sychronized method(){}
?? 4.sychronized() {}
4.? 書上沒說過的: Spin? Lock (旋轉鎖)