Home > Back-end >  Concurrent cases advice logging problems
Concurrent cases advice logging problems

Time:04-17

Log in the project with advice, but the request when more data is disorder, how to solve this problem, please?
Here is my code:
` ` ` Java
@ Aspect
@ Component
@ EnableAspectJAutoProxy
Public class AdviceApi {
The @autowired
Private LogAnalyseService LogAnalyseService;

@ Bean
Public LogChannelCall getBean () {
Return new LogChannelCall ();
}

Private ThreadLocal StartTime=new ThreadLocal<> (a);

The @pointcut (" execution (* com API. Controller. *. * (.. )))
Public void pointcut () {
}

@ Before (pointcut "()")
Public void before () {
It request=((ServletRequestAttributes) RequestContextHolder getRequestAttributes ())
GetRequest ();
String userId=request. The getParameter (" userId ");
String remoteAddr=request. GetRemoteAddr ();

LogChannelCall. SetUserId (userId);
LogChannelCall. SetIp (remoteAddr);
StartTime. Set (System. CurrentTimeMillis ());
}

@ After (pointcut "()")
Public void after () {
HttpServletResponse response=((ServletRequestAttributes) RequestContextHolder getRequestAttributes ()). The method getResponse ();
Boolean successful=response. GetStatus ()==200;
LogChannelCall. SetSuccessful (successful);
}

@ AfterReturning (pointcut "()")
Public void afterReturning () {
LogChannelCall. SetSuccessful (true);
LogChannelCall. SetResponseTime (System. CurrentTimeMillis () - startTime. The get ());
LogAnalyseService. InsertV3Log (logChannelCall);
}

@ AfterThrowing (throwing="ex", pointcut="pointcut () & amp; & ! PointcutPlayAddress () & amp; & ! PointcutInnerPlayAddress () & amp; & ! PointcutProAddress () ")
Public void afterThrowing Exception (ex) {
LogChannelCall. SetSuccessful (false);
LogChannelCall. SetReason (ex. GetMessage ());
LogChannelCall. SetResponseTime (System. CurrentTimeMillis () - startTime. The get ());
LogAnalyseService. InsertV3Log (logChannelCall);
}
}
` ` `

In A large quantity of requests, A log parameters will place B log parameters recorded, A few days ago happened such A thing, A request is executing, B request to the abnormal, B request error log is A record, how do I solve?
  • Related