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
c49b7b0e
Commit
c49b7b0e
authored
May 13, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复等待时间
parent
0ed3022a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
7 deletions
+38
-7
AspectLogTime.java
...rc/main/java/com/yanzuoguang/cloud/aop/AspectLogTime.java
+38
-7
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogTime.java
View file @
c49b7b0e
...
@@ -2,6 +2,8 @@ package com.yanzuoguang.cloud.aop;
...
@@ -2,6 +2,8 @@ package com.yanzuoguang.cloud.aop;
import
com.yanzuoguang.util.base.CollectionString
;
import
com.yanzuoguang.util.base.CollectionString
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.thread.ThreadNext
;
import
com.yanzuoguang.util.thread.ThreadNext
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -18,13 +20,38 @@ import java.util.List;
...
@@ -18,13 +20,38 @@ import java.util.List;
@Component
@Component
public
class
AspectLogTime
implements
ThreadNext
.
Next
,
InitializingBean
{
public
class
AspectLogTime
implements
ThreadNext
.
Next
,
InitializingBean
{
private
final
MemoryCache
<
AspectUrlCountVo
>
memoryCache
=
new
MemoryCache
<>();
/**
* 今日缓存,超过时间会自动清空
*/
private
final
MemoryCache
<
AspectUrlCountVo
>
todayMemoryCache
=
new
MemoryCache
<>();
/**
* 今日日期
*/
private
String
today
;
/**
* 今日时间
*/
private
String
todayTime
;
@Override
@Override
public
void
afterPropertiesSet
()
{
public
void
afterPropertiesSet
()
{
ThreadNext
.
start
(
this
,
"aspectLogTime"
);
ThreadNext
.
start
(
this
,
"aspectLogTime"
);
}
}
private
void
initToday
()
{
String
today
=
DateHelper
.
getToday
();
if
(!
StringHelper
.
compare
(
this
.
today
,
today
))
{
synchronized
(
todayMemoryCache
)
{
if
(!
StringHelper
.
compare
(
this
.
today
,
today
))
{
todayMemoryCache
.
clear
();
this
.
today
=
today
;
this
.
todayTime
=
DateHelper
.
getNow
();
}
}
}
}
/**
/**
* 获取缓存对象
* 获取缓存对象
*
*
...
@@ -32,17 +59,21 @@ public class AspectLogTime implements ThreadNext.Next, InitializingBean {
...
@@ -32,17 +59,21 @@ public class AspectLogTime implements ThreadNext.Next, InitializingBean {
* @return 缓存对象
* @return 缓存对象
*/
*/
private
AspectUrlCountVo
getCount
(
String
url
)
{
private
AspectUrlCountVo
getCount
(
String
url
)
{
AspectUrlCountVo
ret
=
memoryCache
.
get
(
url
);
// 初始化日期
initToday
();
// 缓存中获取对象
AspectUrlCountVo
ret
=
todayMemoryCache
.
get
(
url
);
if
(
ret
!=
null
)
{
if
(
ret
!=
null
)
{
return
ret
;
return
ret
;
}
}
synchronized
(
memoryCache
)
{
// 缓存中不存在则创建对象
ret
=
memoryCache
.
get
(
url
);
synchronized
(
todayMemoryCache
)
{
ret
=
todayMemoryCache
.
get
(
url
);
if
(
ret
!=
null
)
{
if
(
ret
!=
null
)
{
return
ret
;
return
ret
;
}
}
ret
=
new
AspectUrlCountVo
(
url
);
ret
=
new
AspectUrlCountVo
(
url
);
m
emoryCache
.
put
(
url
,
ret
);
todayM
emoryCache
.
put
(
url
,
ret
);
return
ret
;
return
ret
;
}
}
}
}
...
@@ -71,12 +102,12 @@ public class AspectLogTime implements ThreadNext.Next, InitializingBean {
...
@@ -71,12 +102,12 @@ public class AspectLogTime implements ThreadNext.Next, InitializingBean {
@Override
@Override
public
boolean
next
()
{
public
boolean
next
()
{
List
<
AspectUrlCountVo
>
rowList
=
new
ArrayList
<>(
m
emoryCache
.
getValues
());
List
<
AspectUrlCountVo
>
rowList
=
new
ArrayList
<>(
todayM
emoryCache
.
getValues
());
if
(
rowList
.
isEmpty
())
{
if
(
rowList
.
isEmpty
())
{
return
true
;
return
true
;
}
}
rowList
.
sort
(
Comparator
.
comparingInt
(
AspectUrlCountVo:
:
getStartCount
));
rowList
.
sort
(
Comparator
.
comparingInt
(
AspectUrlCountVo:
:
getStartCount
));
System
.
out
.
println
(
CollectionString
.
getCollectionString
(
"接口执行次数:"
,
rowList
));
System
.
out
.
println
(
CollectionString
.
getCollectionString
(
"接口
从"
+
todayTime
+
"时
执行次数:"
,
rowList
));
return
true
;
return
true
;
}
}
...
...
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