# Clear lock owner and lock exp time from act\_ru\_job

**URL:** <https://forum.flowable.org/t/clear-lock-owner-and-lock-exp-time-from-act-ru-job/10465>\
**Category:** Flowable Engine\
**Created:** [May 3, 2023, 2:11pm UTC](https://forum.flowable.org/t/clear-lock-owner-and-lock-exp-time-from-act-ru-job/10465 "2023-05-03T14:11:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IvanDimitrov](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/ivandimitrov/32/3164_2.png) [@IvanDimitrov](https://forum.flowable.org/u/IvanDimitrov)\
**Post date:** [May 3, 2023, 2:11pm UTC](https://forum.flowable.org/t/clear-lock-owner-and-lock-exp-time-from-act-ru-job/10465/1 "2023-05-03T14:11:14Z")

</div>

Hello Flowable colleagues,

I’m looking for a way to manually clear the lock\_owner\_ and lock\_exp\_time\_ from act\_ru\_job for a particular lock\_owner\_. Is this possible with the ProcessEngine or the ManagementService? I did not find a command which clears them. The “ClearProcessInstanceLockTimesCmd” command only clears the process lock\_owner and time from act\_ru\_execution but the jobs are still locked in act\_ru\_job.

The main issue is that when a flowable engine crashes the lock is not cleared and another async executor will execute the job when the lock\_time expires, but in our case, this is 30 minutes. It is not really possible to lower this value because there are jobs that may run for around 30 minutes.

Currently, we have a logic that runs “ClearProcessInstanceLockTimesCmd” when a flowable engine (app instance - it is running on Cloud Foundry) crashes, but this is not enough to unlock the job because this command does not remove the lock\_owners from act\_ru\_job.

Basically, I’m looking for the equivalent of the following query that is implemented by a Command that can be executed from the processEngine, because we want to refrain from using jdbc:  
update act\_ru\_job set lock\_owner\_ = null, lock\_exp\_time\_ = null where lock\_onwer\_ = ?;

Looking forward to hearing from you!

Thanks and best regards,  
Ivan

Flowable - 6.6.0  
DB - Postgresql

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [May 3, 2023, 3:32pm UTC](https://forum.flowable.org/t/clear-lock-owner-and-lock-exp-time-from-act-ru-job/10465/2 "2023-05-03T15:32:14Z")

</div>

Not out of the box, but you could implement your own Command, and then execute it through the ManagementService.

Have a look at e.g. [UnlockTimerJobsCmd](https://github.com/flowable/flowable-engine/blob/main/modules/flowable-job-service/src/main/java/org/flowable/job/service/impl/cmd/UnlockTimerJobsCmd.java), but then for a regular job.

---

<div class="post-metadata">

**Author:** ![IvanDimitrov](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/ivandimitrov/32/3164_2.png) [@IvanDimitrov](https://forum.flowable.org/u/IvanDimitrov)\
**Post date:** [May 5, 2023, 12:33pm UTC](https://forum.flowable.org/t/clear-lock-owner-and-lock-exp-time-from-act-ru-job/10465/3 "2023-05-05T12:33:08Z")

</div>

Hi,  
Thank you!  
The following implementation worker for me. The jobs get unlocked:

```auto
public class ClearJobLockOwnersCmd implements Command<Void> {

    private final List<Job> lockedJobs;
    private final JobServiceConfiguration jobServiceConfiguration;

    public ClearJobLockOwnersCmd(List<Job> lockedJobs, JobServiceConfiguration jobServiceConfiguration) {
        this.lockedJobs = lockedJobs;
        this.jobServiceConfiguration = jobServiceConfiguration;
    }

    @Override
    public Void execute(CommandContext commandContext) {
        JobEntityManager jobEntityManager = jobServiceConfiguration.getJobEntityManager();
        for (Job job : lockedJobs) {
            JobEntity runningLockedJob = jobEntityManager.findById(job.getId());
            if (runningLockedJob != null) {
                runningLockedJob.setLockOwner(null);
                runningLockedJob.setLockExpirationTime(null);
            }
        }
        return null;
    }

}

// Get the JobServiceConfiguration:
processEngine.getProcessEngineConfiguration()
             .getAsyncExecutor()
             .getJobServiceConfiguration();

// Get the Jobs:
processEngine.getManagementService()
             .createJobQuery()
             .lockOwner(lockOwner)
             .list();

// Execute the job:
processEngine.getManagementService()
             .executeCommand(new ClearJobLockOwnersCmd(jobs, jobServiceConfiguration));

```
