Skip navigation links

Package com.kabira.platform.swtimer

Transactional timer service

See: Description

Package com.kabira.platform.swtimer Description

Transactional timer service

Provides a transactional timer service.

Starting, stopping, and canceling timers is transactional, ensuring that the action is atomic. Timer notifiers are also executed in a transaction. The timer service is deadlock safe - the current timer action is rolled back and replayed if a deadlock occurs.

The default resolution of the timers is one second. This may be changed through configuration.

The timer expiration times are stored as absolute times, thus lowering the possibility of timer drift.

Chaining one-shot timers with a fixed interval will appear to drift because the one-shot timer is not scheduled until after the completion of the previous one-shot timer. The notifier will execute following the next whole time interval based on the current timer resolution.

For example, if the timer resolution is one second, and a one-shot-timer is scheduled to execute one-second after firing, the timer notifier will execute two seconds later. It will not fire after the first second because not a whole second has expired (timer resolution in this example is one second). Part of the first second was consumed by the notifier execution time. The next whole interval based on the resolution is the next second, i.e. two seconds later.

Setting a timer for 0 seconds (or milliseconds) will result in the timer being executed at the next timer resolution interval.

A caller specified Object parameter is provided to the notifier, allowing a single instance of the notifier to be shared for multiple uses.

Timer actions are transactional. They do not take effect until the transaction commits.

Configuration

There is configurable control, on a per-JVM basis for the amount of parallelism in the execution of timer notifications, and for the resolution of timers. These settings are both optional.

                        JVM
                        {
                                jvmName = "com_kabira_examples_chat_Main0";
                                timerParallelism = 4;
                                timerResolutionMilliseconds = 500;
                        };
                        

timerParallelism controls the maximum number of parallel time notification executions. timerParallelism is an integer value from 1 to 1000. When not explicitly configured, timerParallelism defaults to a value of 1.

timerResolutionMilliseconds controls the resolution of timers by setting the interval at which timers are examined by the system. When not explicitly configured, timerResolutionMilliseconds defaults to a value of 1000, yielding a timer resolution of 1 second (1000 milliseconds).

Timer resolution is only approximate and cannot be guaranteed. It depends upon the resolution of operating system services and system load.

Warning

Timer operations cannot be called from a commit notifier. This will cause a fatal runtime exception.

Configuring timerResolutionMilliseconds to values smaller than 1000 will increase CPU usage.
Skip navigation links
Copyright 2008-2015 Cloud Software Group, Inc.