同步对象

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
}

objects 的情况下,它可能在对象的类上同步,而不是在单例实例上同步。