Scala Language synchronized synchronize on an object


Example

synchronized is a low-level concurrency construct that can help preventing multiple threads access the same resources. Introduction for the JVM using the Java language.

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
}

In case of objects it might synchronize on the class of the object, not on the singleton instance.