February 2018
Intermediate to advanced
350 pages
7h 35m
English
From Java 5 and onwards, we have access to some atomic thread safe structures, that are still useful with coroutines:
import java.util.concurrent.atomic.AtomicIntegerfun main(args: Array<String>) = runBlocking { val counter = AtomicInteger(0) val time = measureTimeMillis { repeatInParallel(1_000_000) { counter.incrementAndGet() } } println("counter = ${counter.get()}") println("time = $time")}
AtomicInteger gives us many atomic operations that are thread safe. There are more thread safe structures such as other atomic primitives and concurrent collections.
Read now
Unlock full access