Class Schedulers


  • public class Schedulers
    extends java.lang.Object
    Kalix default schedulers.

    These schedulers are used by default by all parts of the Kalix library that need scheduling capabilities to operate. They are started up automatically when this class is loaded for the first time, and are shut down automatically when the application is terminated via an OS interrupt signal or by calling System.exit(int).

    Two default schedulers are provided, a fixed and a dynamic. The former is fixed in the sense that it contains a fixed number of pooled threads, chosen to make optimal use of the number of available system CPUs, while the latter is dynamic in the sense that it will contain as many threads as are necessary to prevent pending jobs from having to wait before being executed.

    Use of the fixed scheduler is preferred for all operations that are non-blocking, which means that they will never suspend the current thread for significant amounts of time (such as for longer than 0.1ms). The reason for the fixed scheduler being preferred is that it makes better use of available CPU resources by switching less between threads, which is a relatively costly operation. As, however, not all operations can be designated as non-blocking, such as old Java I/O calls, JDBC calls, long-running computations, and so on, the dynamic scheduler exists as an alternative. If not used frequently enough, the dynamic scheduler will not contain any cached threads at all, which avoids the costs incurred by context-switching.

    Furthermore, as a way to minimize synchronization between threads, the fixed size scheduler guarantees that if a job is scheduled by one of its pooled threads, the job will be executed by the thread that scheduled it.