同步物件
synchronized
是一個低階併發構造,可以幫助防止多個執行緒訪問相同的資源。使用 Java 語言的 JVM 簡介 。
anInstance.synchronized {
// code to run when the intristic lock on `anInstance` is acquired
// other thread cannot enter concurrently unless `wait` is called on `anInstance` to suspend
// other threads can continue of the execution of this thread if they `notify` or `notifyAll` `anInstance`'s lock
}
在 object
s 的情況下,它可能在物件的類上同步,而不是在單例例項上同步。