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
trydofor
-
-
Constructor Summary
Constructors Constructor Description MysqlServerLock(JdbcTemplate jdbcTemplate, String lockName)
-
Method Summary
Modifier and Type Method Description voidlock()Tries to obtain a lock with a name given by the string str, using a timeout of timeout seconds. booleantryLock()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). booleantryLock(long time, @NotNull() TimeUnit unit)voidunlock()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. voidlockInterruptibly()ConditionnewCondition()-
-
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.
-
lockInterruptibly
void lockInterruptibly()
-
newCondition
@NotNull() Condition newCondition()
-
-
-
-