Re: [問題] 請問synchronized的種類

看板java作者 (!H45)時間19年前 (2006/12/16 12:58), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《Theseus914 (Theseus)》之銘言: : 請問Java中的synchronized 是屬於 : 1. busy waiting semphore : 2. suspend and wakup semphore : 還是都不是 : 希望板上有人可以為我解答 謝謝 suspend and wakeup semphore * First, it is not possible for two invocations of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object, all other threads that invoke synchronized methods for the same object block (suspend execution) until the first thread is done with the object. * Second, when a synchronized method exits, it automatically establishes a happens-before relationship with any subsequent invocation of a synchronized method for the same object. This guarantees that changes to the state of the object are visible to all threads. Ref: http://java.sun.com/docs/books/tutorial/essential/concurrency/syncmeth.html -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.205.85
文章代碼(AID): #15WtpilX (java)
文章代碼(AID): #15WtpilX (java)