Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-cloud-core
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xingmin
yd-cloud-core
Commits
6d03b2ba
Commit
6d03b2ba
authored
Apr 23, 2026
by
zhangxingmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Redisson 分布式锁
parent
8fa54bc1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
16 deletions
+2
-16
yd-framework/src/main/java/com/yd/framework/config/LockExecutor.java
+2
-16
No files found.
yd-framework/src/main/java/com/yd/framework/config/LockExecutor.java
View file @
6d03b2ba
...
@@ -18,10 +18,7 @@ public class LockExecutor {
...
@@ -18,10 +18,7 @@ public class LockExecutor {
private
RedissonClient
redissonClient
;
private
RedissonClient
redissonClient
;
/**
/**
* 在锁保护下执行无返回值的操作(阻塞直到获取锁)
* 在锁保护下执行无返回值的操作(阻塞直到获取锁,自动续期)
*
* @param lockKey 锁的 key
* @param action 要执行的操作
*/
*/
public
void
executeWithLock
(
String
lockKey
,
Runnable
action
)
{
public
void
executeWithLock
(
String
lockKey
,
Runnable
action
)
{
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
...
@@ -37,11 +34,6 @@ public class LockExecutor {
...
@@ -37,11 +34,6 @@ public class LockExecutor {
/**
/**
* 在锁保护下执行有返回值的操作(阻塞直到获取锁)
* 在锁保护下执行有返回值的操作(阻塞直到获取锁)
*
* @param lockKey 锁的 key
* @param supplier 要执行的操作
* @param <T> 返回值类型
* @return 操作结果
*/
*/
public
<
T
>
T
executeWithLock
(
String
lockKey
,
Supplier
<
T
>
supplier
)
{
public
<
T
>
T
executeWithLock
(
String
lockKey
,
Supplier
<
T
>
supplier
)
{
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
...
@@ -56,13 +48,7 @@ public class LockExecutor {
...
@@ -56,13 +48,7 @@ public class LockExecutor {
}
}
/**
/**
* 尝试获取锁,支持等待超时,超时后返回 false 或抛异常(由调用方决定)
* 尝试获取锁,支持等待超时,超时后返回 false(不执行操作)
*
* @param lockKey 锁的 key
* @param waitTime 最大等待时间
* @param unit 时间单位
* @param action 要执行的操作
* @return 是否成功获取锁并执行操作
*/
*/
public
boolean
tryExecuteWithLock
(
String
lockKey
,
long
waitTime
,
TimeUnit
unit
,
Runnable
action
)
{
public
boolean
tryExecuteWithLock
(
String
lockKey
,
long
waitTime
,
TimeUnit
unit
,
Runnable
action
)
{
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment