This document describes a typical application area of a Sync object. It describes how a Sync object controls access to a resource (such as a databaseA database is an organized collection of data including relevant data structures.).
This example is based on the following assumptions:
* A maximum of 3 tasks can access the database
simultaneously.
* Exclusive database access by one task should also be possible.
Due to the fact that you can define states, values and actions, there are numerous fields of application. This example focuses on the principles of using Sync objects.
1. | Creating a Sync Object |
---|
The Sync object should be able to assume two states:
Open the Sync tab and specify the two states including a description. Any names of your choice can be used. States are associated with values. In this example, the value "0" is used for the first status (an individual task exclusively uses the database), the second one can assume values between "0" (no task is using the database) and "3" (max. 3 tasks can access the database at the same time). These numbers are not explicitly written to the Sync object, they are integrated as soon as actions are defined (see below in this document).
The following illustration shows the task (job DB.USE) that should be synchronized. As all executable objects, it includes a Sync tab that can be used to specify Sync objects and the actions that change the particular Sync object's status.
In the Sync object, now define 4 ACTIONS:
Enter these actions in the bottom area of the Sync tab. Any names of your choice are possible. The Defined states table shows the states that you have already defined. We have defined the values shown below, but they do not yet exist in writing:
These are the required actions in the Defined actions table described in detail:
USE
The action USE can be triggered if the Sync object is in the status SHARE
with a value below three. This action keeps the current status, but the
value increases by one. This action is intended for normal tasks which
access the database. These tasks check whether multiple database
usage is possible. Also, they check if the value lies below three because
only three tasks are allowed to access the database simultaneously (in
accordance with the definitions made in this example). The value increases
by one because one more task is now using the database.
USE_EXCLUSIVE
The action USE_EXCLUSIVE can be triggered when the Sync object is in the
status SHARE with value zero. This action is only possible if no other
task uses the database. It sets the status EXCLUSIVE, hence no other task
must use the database.
RELEASE
There are two different specifications of RELEASE. The first RELEASE action
refers to the status SHARE which must have a value greater than zero.
A "normal" task has used the database and is now terminating.
The existing status remains, but the value decreases by one. The second
specification of the RELEASE action refers to the status EXCLUSIVE. A
task which has exclusively used the database now terminates and in doing
so, shared database use is possible again.
All the actions described above are specified in the table shown below:
Finally, click the "Attributes" tab which shows the Sync object's current status and value. Select a start status before you integrate this Sync object in a task. In this example, the start status is "SHARE" with value "0". Store and close the Sync object.
2. |
Integrating the Sync Object in a Task |
---|
This step shows how a Sync object is integrated in tasks. The illustration below shows a job that uses the Sync object to access the database. The job starts and executes the action "USE". It checks whether the database can currently be used multiple times (shared use) and counts the number of tasks using it. The job can only be started if fewer than three tasks are using the database. The action defined in "Else" is processed if the limit of 3 tasks has been reached. In this case, the job waits until one of these tasks has ended. As soon as that occurs, the waiting job starts, and either accesses the database successfully or aborts and the action "RELEASE" is processed.
The following job uses the Sync object to access the database exclusively. The status "EXCLUSIVE" has been specified as the start status. In doing so, no other task can access the database. This start action, however, is only possible if no other task currently uses the database. The action "RELEASE" again releases the database for multiple uses.
See also:
Sync Objects
Synchronizing Tasks in Different Workflows