Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
71025170
authored
Mar 10, 2017
by
xueli.xue
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
执行器"轮训"和"LRU"策略中新增缓存Clear逻辑;
parent
1c5a8415
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRound.java
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteLRU.java
View file @
71025170
...
...
@@ -16,10 +16,18 @@ import java.util.concurrent.ConcurrentHashMap;
public
class
ExecutorRouteLRU
extends
ExecutorRouter
{
private
static
ConcurrentHashMap
<
Integer
,
LinkedHashMap
<
String
,
String
>>
jobLRUMap
=
new
ConcurrentHashMap
<
Integer
,
LinkedHashMap
<
String
,
String
>>();
private
static
long
CACHE_VALID_TIME
=
0
;
@Override
public
String
route
(
int
jobId
,
ArrayList
<
String
>
addressList
)
{
// cache clear
if
(
System
.
currentTimeMillis
()
>
CACHE_VALID_TIME
)
{
jobLRUMap
.
clear
();
CACHE_VALID_TIME
=
System
.
currentTimeMillis
()
+
1000
*
60
*
60
*
24
;
}
// init lru
LinkedHashMap
<
String
,
String
>
lruItem
=
jobLRUMap
.
get
(
jobId
);
if
(
lruItem
==
null
)
{
/**
...
...
@@ -31,12 +39,14 @@ public class ExecutorRouteLRU extends ExecutorRouter {
jobLRUMap
.
put
(
jobId
,
lruItem
);
}
// put
for
(
String
address:
addressList
)
{
if
(!
lruItem
.
containsKey
(
address
))
{
lruItem
.
put
(
address
,
address
);
}
}
// load
String
eldestKey
=
lruItem
.
entrySet
().
iterator
().
next
().
getKey
();
String
eldestValue
=
lruItem
.
get
(
eldestKey
);
return
eldestValue
;
...
...
xxl-job-admin/src/main/java/com/xxl/job/admin/core/route/strategy/ExecutorRouteRound.java
View file @
71025170
...
...
@@ -11,7 +11,15 @@ import java.util.concurrent.ConcurrentHashMap;
public
class
ExecutorRouteRound
extends
ExecutorRouter
{
private
static
ConcurrentHashMap
<
Integer
,
Integer
>
routeCountEachJob
=
new
ConcurrentHashMap
<
Integer
,
Integer
>();
private
static
long
CACHE_VALID_TIME
=
0
;
private
static
int
count
(
int
jobId
)
{
// cache clear
if
(
System
.
currentTimeMillis
()
>
CACHE_VALID_TIME
)
{
routeCountEachJob
.
clear
();
CACHE_VALID_TIME
=
System
.
currentTimeMillis
()
+
1000
*
60
*
60
*
24
;
}
// count++
Integer
count
=
routeCountEachJob
.
get
(
jobId
);
count
=
(
count
==
null
)?
0
:++
count
;
routeCountEachJob
.
put
(
jobId
,
count
);
...
...
@@ -20,6 +28,9 @@ public class ExecutorRouteRound extends ExecutorRouter {
@Override
public
String
route
(
int
jobId
,
ArrayList
<
String
>
addressList
)
{
return
addressList
.
get
(
count
(
jobId
)%
addressList
.
size
());
}
...
...
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