Example 1: Three jobs using the same lock, one of them exclusive

  • First you have to create a lock then it can be acquired by jobs.
  • For example open the folder ./live/lockExample/ in JOE.
  • We create the lock testLock



and three jobs job1, job2, job3 where job1 uses the testLock exclusive and the other jobs use lock non exclusive.


You can download this Example here.

We start the jobs in different orders to see what happens:

  1. job1 -> job2 -> job3
    In this case job1 holds the lock exclusively and job2 and job3 won't start until job1 is completed and will release the lock.
  2. job2 -> job3 -> job1
    In this case job2 and job3 start both because they can get hold of the lock non-exclusively. job1 wants to use the lock exclusively so it doesn't start until job2 and job3 are completed and will release the lock.
  3. job2 -> job1 -> job3
    Same behaviour as for case 2.

Example 2: Number of maximum non-exclusive jobs (useful for maintenance windows)

We assume a lock maintain with an unlimited number of non-exclusive jobs and we assume the jobs job1 and job2 to have acquired the lock maintain in non-exclusive mode.

See above how to create the lock in JOE and how to assign the lock to a job in non-exclusive mode.

Both jobs start in the same way as without the lock because they use it non-exclusively and the maximum number of non-exclusive jobs is unlimited as the lock is configured for unlimited non-exclusive use.

In this example a job chain is added with a job that modifies the maximum number of non-exclusive jobs. This job chain has two orders:

  • For one order the job sets the maximum number of non-exclusive locks to 0 (zero).
  • For the other order the job sets the maximum number of non-exclusive jobs to unlimited (2^31-1).

If the maximum number of non-exclusive jobs equals zero then no job will start that uses this lock.

Therefore with the sample you receive one order is used to to lock both jobs and another order is used to release the jobs.
If a job uses a schedule that is configured to start the job while it is locked then the job is moved to a task queue for later execution.
As soon as the job is released then all planned starts from the task queue are executed.

We assume that you have jobs that required the same resources, e.g. a database table or the same remote host for SSH jobs, and that you would assign them the same lock.
If this resource is not available for a specific time then this example shows a way how to lock these jobs.
This example is further a possible method for a planned maintenance.

Related Downloads

See also