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
aa671aaa
Commit
aa671aaa
authored
May 12, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复等待时间
parent
d22eb0ba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
6 deletions
+30
-6
ThreadHelper.java
...c/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
+22
-1
AspectLogResult.java
.../main/java/com/yanzuoguang/cloud/aop/AspectLogResult.java
+4
-2
LogLocal.java
...src/main/java/com/yanzuoguang/cloud/aop/log/LogLocal.java
+4
-3
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/thread/ThreadHelper.java
View file @
aa671aaa
package
com
.
yanzuoguang
.
util
.
thread
;
package
com
.
yanzuoguang
.
util
.
thread
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.function.Predicate
;
/**
/**
* 线程帮助类
* 线程帮助类
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
ThreadHelper
{
public
class
ThreadHelper
{
...
@@ -237,4 +239,23 @@ public class ThreadHelper {
...
@@ -237,4 +239,23 @@ public class ThreadHelper {
});
});
}
}
/**
* 等待条件是否满足
*
* @param waitMax 等待最大值
* @param waitItem 每次等待值
* @param cond 判断等待条件(已等待时间)
*/
public
static
void
waitRun
(
long
waitMax
,
int
waitItem
,
Predicate
<
Long
>
cond
)
{
long
waitStart
=
System
.
currentTimeMillis
();
long
waitTime
=
0
;
while
(
cond
.
test
(
waitTime
))
{
// 等待线程同步,超过该时间则不继续等待
ThreadHelper
.
sleep
(
waitItem
);
waitTime
=
System
.
currentTimeMillis
()
-
waitStart
;
if
(
waitTime
>
waitMax
)
{
break
;
}
}
}
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogResult.java
View file @
aa671aaa
...
@@ -20,6 +20,8 @@ import org.springframework.stereotype.Component;
...
@@ -20,6 +20,8 @@ import org.springframework.stereotype.Component;
@Component
@Component
public
class
AspectLogResult
{
public
class
AspectLogResult
{
public
static
final
int
WAIT_MAX
=
30
;
public
static
final
int
WAIT_ITEM
=
10
;
private
final
CloudConfig
cloudConfig
;
private
final
CloudConfig
cloudConfig
;
private
final
LogLocal
logLocal
;
private
final
LogLocal
logLocal
;
private
final
AspectLogBody
aspectLogBody
;
private
final
AspectLogBody
aspectLogBody
;
...
@@ -50,9 +52,9 @@ public class AspectLogResult {
...
@@ -50,9 +52,9 @@ public class AspectLogResult {
public
void
responseLog
(
Class
<?>
cls
,
String
tag
,
String
url
,
boolean
logFlag
,
long
start
,
public
void
responseLog
(
Class
<?>
cls
,
String
tag
,
String
url
,
boolean
logFlag
,
long
start
,
Object
requestBody
,
Object
result
,
Exception
resultEx
,
LogVo
log
)
{
Object
requestBody
,
Object
result
,
Exception
resultEx
,
LogVo
log
)
{
try
{
try
{
ThreadHelper
.
waitRun
(
WAIT_MAX
,
WAIT_ITEM
,
k
->
StringHelper
.
isEmpty
(
log
.
getLogId
()));
if
(
StringHelper
.
isEmpty
(
log
.
getLogId
()))
{
if
(
StringHelper
.
isEmpty
(
log
.
getLogId
()))
{
// 等待线程同步,超过该时间则不继续等待
return
;
ThreadHelper
.
sleep
(
30
);
}
}
String
body
=
aspectLogBody
.
getBodyString
(
requestBody
);
String
body
=
aspectLogBody
.
getBodyString
(
requestBody
);
if
(!
StringHelper
.
compare
(
log
.
getContent
(),
body
))
{
if
(!
StringHelper
.
compare
(
log
.
getContent
(),
body
))
{
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/log/LogLocal.java
View file @
aa671aaa
...
@@ -66,15 +66,16 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
...
@@ -66,15 +66,16 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* @param content 请求内容
* @param content 请求内容
*/
*/
public
void
startLog
(
LogVo
log
,
String
actionKey
,
String
actionSubKey
,
String
content
)
{
public
void
startLog
(
LogVo
log
,
String
actionKey
,
String
actionSubKey
,
String
content
)
{
// 声明超时对象
Timeout
<
LogVo
>
time
=
new
Timeout
<>(
log
);
log
.
setCreateDate
(
DateHelper
.
getDateTimeString
(
new
Date
(
time
.
getStart
())));
// 写入其他对象
// 写入其他对象
log
.
setActionKey
(
actionKey
);
log
.
setActionKey
(
actionKey
);
log
.
setActionSubKey
(
actionSubKey
);
log
.
setActionSubKey
(
actionSubKey
);
log
.
setContent
(
content
);
log
.
setContent
(
content
);
// 声明超时对象
Timeout
<
LogVo
>
time
=
new
Timeout
<>(
log
);
log
.
setCreateDate
(
DateHelper
.
getDateTimeString
(
new
Date
(
time
.
getStart
())));
// 生命日志对象爱嗯
// 生命日志对象爱嗯
log
.
setLogId
(
StringHelper
.
getNewID
());
log
.
setLogId
(
StringHelper
.
getNewID
());
cache
.
put
(
log
.
getLogId
(),
time
);
cache
.
put
(
log
.
getLogId
(),
time
);
}
}
...
...
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