Synchronized
Deprecated
Warning since 1.8
Error since 2.1
Synchronizing methods on a class instance is not supported on platforms other than JVM. If you need to annotate a common method as JVM-synchronized, introduce your own optional-expectation annotation and actualize it with a typealias to kotlin.jvm.Synchronized.
Marks the JVM method generated from the annotated function as synchronized
, meaning that the method will be protected from concurrent execution by multiple threads by the monitor of the instance (or, for static methods, the class) on which the method is defined.
Note that for an extension function, the monitor of the facade class, where it gets compiled to a static method, is used. Therefore, this annotation is recommended to be applied only to member functions and properties.
Since Kotlin
1.0Deprecated
Warning since 1.8
Error since 2.1
Synchronizing methods on a class instance is not supported on platforms other than JVM. If you need to annotate a common method as JVM-synchronized, introduce your own optional-expectation annotation and actualize it with a typealias to kotlin.jvm.Synchronized.
Since Kotlin
1.1Marks the JVM method generated from the annotated function as synchronized
, meaning that the method will be protected from concurrent execution by multiple threads by the monitor of the instance (or, for static methods, the class) on which the method is defined.
Note that for an extension function, the monitor of the facade class, where it gets compiled to a static method, is used. Therefore, this annotation is recommended to be applied only to member functions and properties. In other cases, use synchronized function and explicitly specify the lock to be used.