Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gogirl-miniapp-backend
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
huluobin
gogirl-miniapp-backend
Commits
2128aee1
Commit
2128aee1
authored
Apr 08, 2020
by
huluobin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新预约状态加锁
parent
a8fa342f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletion
+64
-1
ScheduleServeIdLock.java
.../gogirl/infrastructure/util/lock/ScheduleServeIdLock.java
+56
-0
ScheduleManageController.java
...girl/interfaces/order/serve/ScheduleManageController.java
+8
-1
No files found.
src/main/java/com/gogirl/infrastructure/util/lock/ScheduleServeIdLock.java
0 → 100644
View file @
2128aee1
package
com
.
gogirl
.
infrastructure
.
util
.
lock
;
import
java.util.HashMap
;
import
java.util.concurrent.locks.ReentrantLock
;
/**
* * 分段锁,系统提供一定数量的原始锁,根据传入用户id值获取对应的锁并加锁 * 注意:要锁的用户id值如果发生改变,有可能导致锁无法成功释放!!!
*/
public
class
ScheduleServeIdLock
{
private
final
static
HashMap
<
Integer
,
ReentrantLock
>
lockMap
=
new
HashMap
<>();
private
Integer
segments
=
1
;
// 默认分段数量
private
ScheduleServeIdLock
()
{
init
(
null
,
false
);
}
private
ScheduleServeIdLock
(
Integer
counts
,
boolean
fair
)
{
init
(
counts
,
fair
);
}
/*静态内部类实现单例*/
public
static
final
ScheduleServeIdLock
getInsatance
()
{
return
SingletonHolder
.
instance
;
}
private
void
init
(
Integer
counts
,
boolean
fair
)
{
if
(
counts
!=
null
)
{
segments
=
counts
;
}
for
(
int
i
=
0
;
i
<
segments
;
i
++)
{
lockMap
.
put
(
i
,
new
ReentrantLock
(
fair
));
}
}
public
void
lock
(
int
key
)
{
ReentrantLock
lock
=
lockMap
.
get
(
key
%
segments
);
lock
.
lock
();
}
public
void
unlock
(
int
key
)
{
ReentrantLock
lock
=
lockMap
.
get
(
key
%
segments
);
lock
.
unlock
();
}
@Override
public
String
toString
()
{
return
"SegmentLock [segments="
+
segments
+
", lockMap="
+
lockMap
+
"]"
;
}
/*静态内部类实现单例*/
private
static
class
SingletonHolder
{
private
static
final
ScheduleServeIdLock
instance
=
new
ScheduleServeIdLock
(
null
,
true
);
}
}
src/main/java/com/gogirl/interfaces/order/serve/ScheduleManageController.java
View file @
2128aee1
...
...
@@ -22,6 +22,7 @@ import com.gogirl.infrastructure.common.exception.RRException;
import
com.gogirl.infrastructure.mapper.product.purchase.PurchaseSkuMapper
;
import
com.gogirl.infrastructure.mapper.product.serve.BaseProduceMapper
;
import
com.gogirl.infrastructure.util.SessionUtils
;
import
com.gogirl.infrastructure.util.lock.ScheduleServeIdLock
;
import
com.gogirl.infrastructure.util.lock.ScheduledLock
;
import
com.gogirl.shared.order.serve.command.schedule.CancelScheduleCommand
;
import
com.gogirl.shared.order.serve.command.schedule.SubmitScheduleCommand
;
...
...
@@ -226,7 +227,13 @@ public class ScheduleManageController {
@RequestParam
Integer
scheduleServeId
,
@RequestParam
Integer
status
,
@RequestParam
Integer
forceLeisureConfig
)
{
scheduleManageService
.
updateScheduledServeStatus
(
scheduleServeId
,
status
,
forceLeisureConfig
);
ScheduleServeIdLock
lock
=
ScheduleServeIdLock
.
getInsatance
();
try
{
lock
.
lock
(
scheduleServeId
);
scheduleManageService
.
updateScheduledServeStatus
(
scheduleServeId
,
status
,
forceLeisureConfig
);
}
finally
{
lock
.
unlock
(
scheduleServeId
);
}
return
JsonResult
.
success
();
}
...
...
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