Tutorial by Examples

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 co...
/* within a class, def, trait or object, but not a constructor */ synchronized { /* code to run when an intrisctic lock on `this` is acquired */ /* no other thread can get the this lock unless execution is suspended with * `wait` on `this` */ }

Page 1 of 1