Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
ff2ddd0c
Commit
ff2ddd0c
authored
Apr 29, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分布式幂等性判断
parent
cb0c15c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
1 deletion
+39
-1
CacheLock.java
...-redis/src/main/java/com.yanzuoguang.redis/CacheLock.java
+39
-1
No files found.
yzg-util-redis/src/main/java/com.yanzuoguang.redis/CacheLock.java
View file @
ff2ddd0c
...
@@ -38,7 +38,24 @@ public class CacheLock implements Runnable {
...
@@ -38,7 +38,24 @@ public class CacheLock implements Runnable {
/**
/**
* 执行函数
* 执行函数
*/
*/
private
final
Runnable
func
;
private
Runnable
func
;
/**
* 等待次数
*/
private
int
waitCount
;
/**
* 构造函数
*
* @param cache
* @param lockTime
* @param waitUnitTime
* @param key
*/
public
CacheLock
(
Cache
cache
,
int
lockTime
,
int
waitUnitTime
,
String
key
)
{
this
(
cache
,
lockTime
,
waitUnitTime
,
key
,
null
);
}
/**
/**
* 构造函数
* 构造函数
...
@@ -57,11 +74,31 @@ public class CacheLock implements Runnable {
...
@@ -57,11 +74,31 @@ public class CacheLock implements Runnable {
this
.
func
=
func
;
this
.
func
=
func
;
}
}
/**
* 等待次数
*
* @return
*/
public
int
getWaitCount
()
{
return
waitCount
;
}
/**
* 开始执行,每个关键字会等待其他关键字执行完成后执行
*/
public
void
run
(
Runnable
func
)
{
this
.
func
=
func
;
this
.
run
();
}
/**
/**
* 开始执行,每个关键字会等待其他关键字执行完成后执行
* 开始执行,每个关键字会等待其他关键字执行完成后执行
*/
*/
@Override
@Override
public
void
run
()
{
public
void
run
()
{
if
(
this
.
func
==
null
)
{
return
;
}
// 需要运行的函数
// 需要运行的函数
Runnable
runnable
=
new
Runnable
()
{
Runnable
runnable
=
new
Runnable
()
{
@Override
@Override
...
@@ -76,6 +113,7 @@ public class CacheLock implements Runnable {
...
@@ -76,6 +113,7 @@ public class CacheLock implements Runnable {
cache
.
tryLockAndRun
(
key
,
lockTime
,
TimeUnit
.
SECONDS
,
runnable
);
cache
.
tryLockAndRun
(
key
,
lockTime
,
TimeUnit
.
SECONDS
,
runnable
);
// 假如没有运行,则等待50毫秒后继续运行
// 假如没有运行,则等待50毫秒后继续运行
if
(!
runFlag
)
{
if
(!
runFlag
)
{
this
.
waitCount
++;
ThreadHelper
.
sleep
(
waitUnitTime
);
ThreadHelper
.
sleep
(
waitUnitTime
);
}
}
}
while
(!
runFlag
);
}
while
(!
runFlag
);
...
...
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