Meaning of lockDuration in External Task Client?

What is the Meaning of lockDuration in External Task Client?

As per below code it looks like to me that the task will be locked for 20 seconds (assuming default value).
Does that mean the External Task Client needs to finish it within 20 seconds, else it can also be picked by another task client polling to same topic.


  /**
   * @param lockDuration <ul>
   *                       <li> in milliseconds to lock the external tasks
   *                       <li> must be greater than zero
   *                       <li> the default lock duration is 20 seconds (20,000 milliseconds)
   *                       <li> overrides the lock duration configured on bootstrapping the client
   *                     </ul>
   * @return the builder
   */
  TopicSubscriptionBuilder lockDuration(long lockDuration);

Hi @Himanshu_Singh,

exactly

2 Likes

Link to documentation if it may help: External Tasks | docs.camunda.org

Further question: if I want a task to be locked for ever, what should be the lockDuration value? For instance, for a task sending an email campaign to many recipients, it may take quite a long time to complete, and I don’t want the emails to be sent 2 or 3 or more times to each recipient. This could happen with a “finite” lockDuration

Hi @bfredo123,

a lock forever is not possible, but the lock duration is a long value in milliseconds. ExternalTaskQueryBuilder (Camunda Platform Javadocs 7.18.2-ee)

86400 * 1000 * 365 * 20 = 630.720.000.000, which could be used as a lock duration for 20 years. In case you haven’t finished your tasks in this time, …

Hope this helps, Ingo

1 Like

20 years… well, should be enough as a first approach! :slight_smile:

Seriously: thank you so much Ingo, quite helpful!! I did not find the exact type of the lockDuration by myself