Hitachi

uCosminexus Application Server Compatibility Guide


21.3.1 Methods of scheduling threads by using TimerManager

You use the following two methods for scheduling threads, by using TimerManager:

This section describes an overview of each scheduling method.

Organization of this subsection

(1) Executing the process only once

This is a method that executes the processing only once at a specified time. After the processing is executed, TimerManager is destroyed.

(2) Executing and repeating the process at regular intervals

You use the following two methods to repeatedly execute the process at regular intervals:

The scheduled process continues to execute until you stop TimerManager or until the cancel method of the corresponding Timer is executed.

The following subsection gives an overview of each method:

fixed-rate (Specify interval for starting the process, and then repeatedly execute the process)

This is a method which repeatedly starts the process at regular intervals. Specify the following contents in fixed-rate:

Timing to start the first process

You use one of the following methods to specify the settings:

  • When specifying the start time,

    Use the Date type format to specify the firstTime argument of the scheduleAtFixedRate method.

  • When specifying the elapsed time from the start of an application until execution of the process

    Use the long type format to specify the delay argument of the scheduleAtFixedRate method. The unit is milliseconds.

Interval from the start of the previous process to the start of the next processing

Use the long type format to specify the specify period argument of the scheduleAtFixedRate method. The unit is milliseconds.

The following figure shows an image of fixed-rate process. In this figure, the time from the start of an application to the start of the first process is two seconds, and the time from the start of the previous process to the start of the next process is three seconds.

Figure 21‒3:  Image of fixed-rate processing

[Figure]

With the fixed-rate process, if the process time executed previously is longer than the time specified in the period, the next process is started immediately after the previously executed process ends. In this figure, the time for the third process is longer than three seconds as specified in period, and hence, the fourth process is started immediately after the third process ends.

fixed-delay (Specify an interval from the end of a process to the start of the next process, and then repeatedly execute the process)

This method repeatedly starts the process at regular intervals after the previous process ends. You specify the following contents in fixed-delay.

Timing to start the first process

Use one of the following methods to specify the timing:

  • When specifying the start time

    Use the Date type format to specify firstTime, an argument of the schedule method.

  • When specifying elapsed time from the start of application until execution of the processing

    Use the long type to specify delay, an argument of the schedule method. The unit is milliseconds.

Interval from completion of previous processing to start of next processing

Use the long type to specify period, an argument of the schedule method. The unit is milliseconds.

The following figure shows the image of the fixed-delay process. In this figure, the time from the start of an application to the start of the first process and the time from the end of the previous process to the start of the next process is considered as two seconds.

Figure 21‒4:  Image of the fixed-delay process

[Figure]