Class MysqlServerLock

  • All Implemented Interfaces:
    java.util.concurrent.locks.Lock

    
    public class MysqlServerLock
     implements Lock
                        

    Locks based on the Mysql IS_FREE_LOCK and GET_LOCK at mysql instance level.

    Since:

    2021-03-08

    Author:

    trydofor

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      MysqlServerLock(JdbcTemplate jdbcTemplate, String lockName)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      void lock() Tries to obtain a lock with a name given by the string str, using a timeout of timeout seconds.
      boolean tryLock() Returns 1 if the lock was obtained successfully, 0 if the attempt timed out (for example, because another client has previously locked the name), or NULL if an error occurred (such as running out of memory or the thread was killed with mysqladmin kill).
      boolean tryLock(long time, @NotNull() TimeUnit unit)
      void unlock() Returns 1 if the lock was released, 0 if the lock was not established by this thread (in which case the lock is not released), and NULL if the named lock did not exist.
      void lockInterruptibly()
      Condition newCondition()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MysqlServerLock

        MysqlServerLock(JdbcTemplate jdbcTemplate, String lockName)
    • Method Detail

      • lock

         void lock()

        Tries to obtain a lock with a name given by the string str, using a timeout of timeout seconds. A negative timeout value means infinite timeout. The lock is exclusive. While held by one session, other sessions cannot obtain a lock of the same name.

      • tryLock

         boolean tryLock()

        Returns 1 if the lock was obtained successfully, 0 if the attempt timed out (for example, because another client has previously locked the name), or NULL if an error occurred (such as running out of memory or the thread was killed with mysqladmin kill).

      • tryLock

         boolean tryLock(long time, @NotNull() TimeUnit unit)
      • unlock

         void unlock()

        Returns 1 if the lock was released, 0 if the lock was not established by this thread (in which case the lock is not released), and NULL if the named lock did not exist.