Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
480e325c
Commit
480e325c
authored
May 25, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分布式锁失效
parent
f190a138
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
33 deletions
+39
-33
ApiFlowServiceImpl.java
...c/main/java/com/byit/service/impl/ApiFlowServiceImpl.java
+1
-1
RedissonProperties.java
...ain/java/com/byit/conf/properties/RedissonProperties.java
+1
-1
DaemonScanThreadRunHelperRedisLock.java
.../com/byit/factory/DaemonScanThreadRunHelperRedisLock.java
+9
-5
DistributedLocker.java
...e/src/main/java/com/byit/util/lock/DistributedLocker.java
+3
-8
RedissLockUtil.java
...core/src/main/java/com/byit/util/lock/RedissLockUtil.java
+5
-8
RedissonDistributedLocker.java
...in/java/com/byit/util/lock/RedissonDistributedLocker.java
+20
-10
No files found.
byit-myth-admin/src/main/java/com/byit/service/impl/ApiFlowServiceImpl.java
View file @
480e325c
...
...
@@ -1156,7 +1156,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
try
{
RedissLockUtil
.
lock
(
flow
.
getFlowId
().
toString
(),
60
);
RedissLockUtil
.
trlock
(
flow
.
getFlowId
().
toString
(),
5
);
//设置触发时间
Long
triggerTime
=
System
.
currentTimeMillis
();
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/conf/properties/RedissonProperties.java
View file @
480e325c
...
...
@@ -14,7 +14,7 @@ import java.util.List;
public
class
RedissonProperties
{
private
int
timeout
=
3
000
;
private
int
timeout
=
60
000
;
private
String
address
;
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/factory/DaemonScanThreadRunHelperRedisLock.java
View file @
480e325c
...
...
@@ -41,11 +41,15 @@ public class DaemonScanThreadRunHelperRedisLock extends BaseDaemonScanThreadRunH
Long
sleepTime
=
0L
;
try
{
//加锁
RedissLockUtil
.
lock
(
lockName
,
120
);
log
.
debug
(
"------------{},加锁成功,锁名称为{}----------"
,
threadName
,
lockName
);
dateAligned
(
CYCLE_INTERVAL
,
threadName
);
//调用业务操作
sleepTime
=
examplesValue
.
start
();
boolean
trlock
=
RedissLockUtil
.
trlock
(
lockName
,
10
);
if
(
trlock
)
{
log
.
debug
(
"------------{},加锁成功,锁名称为{}----------"
,
threadName
,
lockName
);
dateAligned
(
CYCLE_INTERVAL
,
threadName
);
//调用业务操作
sleepTime
=
examplesValue
.
start
();
}
else
{
log
.
debug
(
"------------{},加锁失败,锁名称为{}----------"
,
threadName
,
lockName
);
}
}
catch
(
Exception
e
)
{
if
(!
THREAD_GROUP_STOP
){
e
.
printStackTrace
();
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/util/lock/DistributedLocker.java
View file @
480e325c
...
...
@@ -4,12 +4,6 @@ import java.util.concurrent.TimeUnit;
public
interface
DistributedLocker
{
/**
* 加锁
* @param lockKey
*/
void
lock
(
String
lockKey
);
/**
* 解锁
* @param lockKey
*/
...
...
@@ -20,7 +14,7 @@ public interface DistributedLocker {
* @param lockKey
* @param timeout
*/
void
lock
(
String
lockKey
,
int
timeout
);
boolean
tr
lock
(
String
lockKey
,
int
timeout
);
/**
* 带单位的超时时间的加锁
...
...
@@ -28,5 +22,5 @@ public interface DistributedLocker {
* @param unit
* @param timeout
*/
void
lock
(
String
lockKey
,
TimeUnit
unit
,
int
timeout
);
boolean
tr
lock
(
String
lockKey
,
TimeUnit
unit
,
int
timeout
);
}
\ No newline at end of file
byit-myth-core/myth-admin-core/src/main/java/com/byit/util/lock/RedissLockUtil.java
View file @
480e325c
...
...
@@ -16,10 +16,6 @@ public class RedissLockUtil {
public
static
DistributedLocker
getRedissLock
(){
return
RedissLockUtil
.
redissLock
;
}
public
static
void
lock
(
String
lockKey
)
{
redissLock
.
lock
(
lockKey
);
}
public
static
void
unlock
(
String
lockKey
)
{
redissLock
.
unlock
(
lockKey
);
...
...
@@ -30,8 +26,8 @@ public class RedissLockUtil {
* @param lockKey
* @param timeout 超时时间 单位:秒
*/
public
static
void
lock
(
String
lockKey
,
int
timeout
)
{
re
dissLock
.
lock
(
lockKey
,
timeout
);
public
static
boolean
tr
lock
(
String
lockKey
,
int
timeout
)
{
re
turn
redissLock
.
tr
lock
(
lockKey
,
timeout
);
}
/**
...
...
@@ -40,7 +36,7 @@ public class RedissLockUtil {
* @param unit 时间单位
* @param timeout 超时时间
*/
public
static
void
lock
(
String
lockKey
,
TimeUnit
unit
,
int
timeout
)
{
re
dissLock
.
lock
(
lockKey
,
unit
,
timeout
);
public
static
boolean
tr
lock
(
String
lockKey
,
TimeUnit
unit
,
int
timeout
)
{
re
turn
redissLock
.
tr
lock
(
lockKey
,
unit
,
timeout
);
}
}
\ No newline at end of file
byit-myth-core/myth-admin-core/src/main/java/com/byit/util/lock/RedissonDistributedLocker.java
View file @
480e325c
package
com
.
byit
.
util
.
lock
;
import
lombok.extern.slf4j.Slf4j
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
...
...
@@ -9,32 +10,41 @@ import java.util.concurrent.TimeUnit;
* @author huangfu
* redis分布式锁
*/
@Slf4j
public
class
RedissonDistributedLocker
implements
DistributedLocker
{
private
RedissonClient
redissonClient
;
@Override
public
void
lock
(
String
lockKey
)
{
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
lock
.
lock
();
}
@Override
public
void
unlock
(
String
lockKey
)
{
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
lock
.
unlock
();
}
@Override
public
void
lock
(
String
lockKey
,
int
leaseTime
)
{
public
boolean
tr
lock
(
String
lockKey
,
int
leaseTime
)
{
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
lock
.
lock
(
leaseTime
,
TimeUnit
.
SECONDS
);
boolean
lockFlag
=
false
;
try
{
lockFlag
=
lock
.
tryLock
(
leaseTime
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"-----------------{}------------"
,
e
.
getMessage
());
Thread
.
currentThread
().
interrupt
();
}
return
lockFlag
;
}
@Override
public
void
lock
(
String
lockKey
,
TimeUnit
unit
,
int
timeout
)
{
public
boolean
tr
lock
(
String
lockKey
,
TimeUnit
unit
,
int
timeout
)
{
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
lock
.
lock
(
timeout
,
unit
);
boolean
lockFlag
=
false
;
try
{
lockFlag
=
lock
.
tryLock
(
timeout
,
unit
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"-----------------{}------------"
,
e
.
getMessage
());
Thread
.
currentThread
().
interrupt
();
}
return
lockFlag
;
}
public
void
setRedissonClient
(
RedissonClient
redissonClient
)
{
...
...
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