※ 引述《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 ([1msuspend execution[m) 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