August 2018
Beginner
178 pages
4h 56m
English
Sometimes, holding a lock for the entire duration of a function call is too expensive and Java offers to run parts of the code under a lock, again with the synchronized keyword. To achieve the same behavior, Kotlin offers the synchronized function. The function accepts an object that will be locked and a lambda to execute while holding the lock:
fun synchronizedBlock() { // multiple threads can be here synchronized(this) { //only one thread at a time can be here }}
Read now
Unlock full access