Class JdbcLockProvider

  • All Implemented Interfaces:
    LockProvider

    public class JdbcLockProvider
    extends StorageBasedLockProvider
    Lock provided by plain JDBC. It uses a table that contains lock_name and locked_until.
    1. Attempts to insert a new lock record. Since lock name is a primary key, it fails if the record already exists. As an optimization, we keep in-memory track of created lock records.
    2. If the insert succeeds (1 inserted row) 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 record using UPDATE tableName SET lock_until = :lockUntil WHERE name = :lockName AND lock_until <= :now
    4. If the update succeeded (1 updated row), we have the lock. If the update failed (0 updated rows) somebody else holds the lock
    5. When unlocking, lock_until is set to now.
    • Constructor Detail

      • JdbcLockProvider

        public JdbcLockProvider​(@NotNull
                                @NotNull DataSource datasource)
      • JdbcLockProvider

        public JdbcLockProvider​(@NotNull
                                @NotNull DataSource datasource,
                                @NotNull
                                @NotNull String tableName)