java.lang.Object
net.javacrumbs.shedlock.support.StorageBasedLockProvider
net.javacrumbs.shedlock.provider.neo4j.Neo4jLockProvider
All Implemented Interfaces:
ExtensibleLockProvider, LockProvider

public class Neo4jLockProvider extends StorageBasedLockProvider
Lock provided by Neo4j Graph API. It uses a collection that stores each lock as a node.
  1. Attempts to insert a new lock node. Since lock name has a unique constraint, it fails if the record already exists. As an optimization, we keep in-memory track of created lock nodes.
  2. If the insert succeeds (1 node inserted) we have the lock.
  3. If the insert failed due to duplicate key or we have skipped the insertion, we will try to update lock node using MATCH (lock:collectionName) WHERE name = $lockName AND lock_until <= $now SET lock_until = $lockUntil, locked_at = $now with some additional explicit node locking
  4. If the update succeeded (>1 property updated), we have the lock. If the update failed (<=1 properties updated) somebody else holds the lock or grabbed the lock in a data race caused by Neo4j's read-committed isolation level.
  5. When unlocking, lock_until is set to now.
  • Constructor Details

    • Neo4jLockProvider

      public Neo4jLockProvider(org.neo4j.driver.Driver driver)
    • Neo4jLockProvider

      public Neo4jLockProvider(org.neo4j.driver.Driver graphDatabaseService, String collectionName, String databaseName)