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
6eb6d4cf
Commit
6eb6d4cf
authored
Apr 09, 2020
by
huluobin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
考勤申请加锁
parent
bfc6193d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
1 deletion
+64
-1
TechnicianIdLock.java
...com/gogirl/infrastructure/util/lock/TechnicianIdLock.java
+56
-0
TakeLeaveEventController.java
...interfaces/store/attendance/TakeLeaveEventController.java
+8
-1
No files found.
src/main/java/com/gogirl/infrastructure/util/lock/TechnicianIdLock.java
0 → 100644
View file @
6eb6d4cf
package
com
.
gogirl
.
infrastructure
.
util
.
lock
;
import
java.util.HashMap
;
import
java.util.concurrent.locks.ReentrantLock
;
/**
* * 分段锁,系统提供一定数量的原始锁,根据传入用户id值获取对应的锁并加锁 * 注意:要锁的用户id值如果发生改变,有可能导致锁无法成功释放!!!
*/
public
class
TechnicianIdLock
{
private
final
static
HashMap
<
Integer
,
ReentrantLock
>
lockMap
=
new
HashMap
<>();
private
Integer
segments
=
500
;
// 默认分段数量
private
TechnicianIdLock
()
{
init
(
null
,
false
);
}
private
TechnicianIdLock
(
Integer
counts
,
boolean
fair
)
{
init
(
counts
,
fair
);
}
/*静态内部类实现单例*/
public
static
final
TechnicianIdLock
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
TechnicianIdLock
instance
=
new
TechnicianIdLock
(
null
,
true
);
}
}
src/main/java/com/gogirl/interfaces/store/attendance/TakeLeaveEventController.java
View file @
6eb6d4cf
...
@@ -8,6 +8,7 @@ import com.gogirl.domain.store.store.StoreTechnician;
...
@@ -8,6 +8,7 @@ import com.gogirl.domain.store.store.StoreTechnician;
import
com.gogirl.domain.xcx.GogirlToken
;
import
com.gogirl.domain.xcx.GogirlToken
;
import
com.gogirl.infrastructure.common.base.JsonResult
;
import
com.gogirl.infrastructure.common.base.JsonResult
;
import
com.gogirl.infrastructure.util.SessionUtils
;
import
com.gogirl.infrastructure.util.SessionUtils
;
import
com.gogirl.infrastructure.util.lock.TechnicianIdLock
;
import
com.gogirl.shared.store.command.ApplyTakeLeaveCommand
;
import
com.gogirl.shared.store.command.ApplyTakeLeaveCommand
;
import
com.gogirl.shared.store.command.ApprovalTakeLeaveCommand
;
import
com.gogirl.shared.store.command.ApprovalTakeLeaveCommand
;
import
com.gogirl.shared.store.query.qry.PageApplyQuery
;
import
com.gogirl.shared.store.query.qry.PageApplyQuery
;
...
@@ -35,7 +36,13 @@ public class TakeLeaveEventController {
...
@@ -35,7 +36,13 @@ public class TakeLeaveEventController {
public
JsonResult
<
Void
>
applyTakeLeave
(
@RequestHeader
String
token
,
public
JsonResult
<
Void
>
applyTakeLeave
(
@RequestHeader
String
token
,
@RequestBody
ApplyTakeLeaveCommand
cmd
)
{
@RequestBody
ApplyTakeLeaveCommand
cmd
)
{
cmd
.
setApplyTechnicianId
(
SessionUtils
.
getTechnicianId
());
cmd
.
setApplyTechnicianId
(
SessionUtils
.
getTechnicianId
());
takeLeaveEventCmdService
.
applyTakeLeave
(
cmd
);
TechnicianIdLock
lock
=
TechnicianIdLock
.
getInsatance
();
try
{
lock
.
lock
(
cmd
.
getApplyTechnicianId
());
takeLeaveEventCmdService
.
applyTakeLeave
(
cmd
);
}
finally
{
lock
.
unlock
(
cmd
.
getApplyTechnicianId
());
}
return
JsonResult
.
success
();
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