InternalClock

kyo.scheduler.InternalClock
final case class InternalClock(executor: Executor)

Low-resolution clock optimized for frequent access in the scheduler.

While System.currentTimeMillis is accurate, calling it frequently creates significant overhead due to system calls. This clock uses a dedicated thread to update a volatile timestamp every millisecond, allowing other threads to read the current time without system calls.

The tradeoff of potentially being off by up to a millisecond is acceptable for scheduler operations like measuring task runtime and detecting stalled workers. The performance benefit of avoiding system calls on every time check is substantial when processing thousands of tasks per second.

The clock self-corrects any drift by measuring the actual elapsed time between updates.

Value parameters

executor

Executor for running the update thread

Attributes

Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def currentMillis(): Long

Get the current time in milliseconds without making a system call.

Get the current time in milliseconds without making a system call.

This method is designed for frequent calls, returning the latest cached timestamp from the update thread. The returned time has millisecond resolution but may be up to one millisecond behind the system time.

Attributes

Returns

Current time in milliseconds since epoch, accurate to within one millisecond

def stop(): Unit

Stop the clock's update thread.

Stop the clock's update thread.

After stopping, currentMillis() will return the last updated timestamp. The clock cannot be restarted after stopping - create a new instance if needed.

Attributes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product

Concrete fields

val a1: Long
val a2: Long
val a3: Long
val a4: Long
val a5: Long
val a6: Long
val a7: Long
val b1: Long
val b2: Long
val b3: Long
val b4: Long
val b5: Long
val b6: Long
val b7: Long