Synchronizer

class Synchronizer(lock: Any = Any())

The Synchronizer class provides a mechanism to synchronize the execution of code blocks. All blocks of code executed via the same Synchronizer instance will never be running in simultaneously. It uses a lock object to ensure that only one thread can execute the synchronized block at a time. It also tracks the total and maximum time spent in synchronized blocks.

Constructors

Link copied to clipboard
constructor(lock: Any = Any())

Properties

Link copied to clipboard

The maximum time spent in a single synchronized block.

Link copied to clipboard

The total time spent in synchronized blocks.

Functions

Link copied to clipboard
fun <R> doSynced(what: () -> R): R

Executes the given block of code in a synchronized across all threads manner. It also measures the time taken to execute the block and updates the total and maximum time worked for.