Synchronized methods

Java has the synchronized keyword, which can be applied to methods to ensure that only one thread at a time can access them. A thread that enters a synchronized method obtains a lock (an object being locked is the instance of the containing class) and no other thread can enter the method until the lock is released. Kotlin offers the same functionality with the @Synchronized annotation. When applied to a method, it will produce the same bytecode as Java would with the synchronized keyword:

@Synchronized
fun threadSafeFunction() {

}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.247.233