java.lang.Object
net.javacrumbs.shedlock.provider.dynamodb2.DynamoDBLockProvider
All Implemented Interfaces:
net.javacrumbs.shedlock.core.LockProvider

public class DynamoDBLockProvider extends Object implements net.javacrumbs.shedlock.core.LockProvider
Distributed lock using DynamoDB. Depends on software.amazon.awssdk:dynamodb.

It uses a table with the following structure:

 {
    "_id" : "lock name",
    "lockUntil" : ISODate("2017-01-07T16:52:04.071Z"),
    "lockedAt" : ISODate("2017-01-07T16:52:03.932Z"),
    "lockedBy" : "host name"
 }
 
lockedAt and lockedBy are just for troubleshooting and are not read by the code.
  1. Attempts to insert a new lock record.
  2. We will try to update lock record using filter _id == :name AND lock_until <= :now .
  3. If the update succeeded, we have the lock. If the update failed (condition check exception) somebody else holds the lock.
  4. When unlocking, lock_until is set to now or lockAtLeastUntil whichever is later.
  • Constructor Details

    • DynamoDBLockProvider

      public DynamoDBLockProvider(software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient, String tableName)
      Uses DynamoDB to coordinate locks
      Parameters:
      dynamoDbClient - v2 of DynamoDB client
      tableName - the lock table name
  • Method Details

    • lock

      public Optional<net.javacrumbs.shedlock.core.SimpleLock> lock(net.javacrumbs.shedlock.core.LockConfiguration lockConfiguration)
      Specified by:
      lock in interface net.javacrumbs.shedlock.core.LockProvider