July 2018
Intermediate to advanced
242 pages
8h 6m
English
The preceding code is going to print the following text to the console:
Running on mainStarting async operation on Thread-0Ending async operation on Thread-0Starting async operation on Thread-1
Ending async operation on Thread-1main thread is free now
We have successfully started two background threads, which are synchronized. In order to run both background threads sequentially, we are using the Thread.join() function, which just blocks the main thread until the background thread completes. In order to instantiate and start a new background thread, we are using the thread() utility function from the kotlin.concurrent package. We are passing it a block of code to be run inside the thread inside a lambda expression.
Read now
Unlock full access