public void send(String userName) {
try {
/ / QPS to report
qps(params);
long startTime = System.currentTimeMillis();
// Build context (mock business code)
ProcessContext processContext = new ProcessContext();
UserModel userModel = new UserModel();
userModel.setAge("22");
userModel.setName(userName);
/ /...
/ / rt report
long endTime = System.currentTimeMillis();
rt(endTime - startTime);
} catch (Exception e) {
// Error reportingerror(params); }}Copy the code
@Around("@annotation(com.sanwai.service.openapi.monitor.Monitor)")
public Object antispan(ProceedingJoinPoint pjp) throws Throwable {
String functionName = pjp.getSignature().getName();
Map<String, String> tags = new HashMap<>();
logger.info(functionName);
tags.put("functionName", functionName);
tags.put("flag"."done");
monitor.sum(functionName, "start".1);
// Method execution start time
long startTime = System.currentTimeMillis();
Object o = null;
try {
o = pjp.proceed();
} catch (Exception e) {
// Method execution end time
long endTime = System.currentTimeMillis();
tags.put("flag"."fail");
monitor.avg("rt", tags, endTime - startTime);
monitor.sum(functionName, "fail".1);
throw e;
}
// Method execution end time
long endTime = System.currentTimeMillis();
monitor.avg("rt", tags, endTime - startTime);
if (null! = o) { monitor.sum(functionName,"done".1);
}
return o;
}
Copy the code
The article is explained from the perspective of pure interview, so there are many details that are not foreshadowed.
Such as reflection,.Java files to JVM procedures, what AOP is, etc… All of these are detailed in Java3y in basic tutorials and even e-books, which I won’t go into.
Welcome to follow my wechat official account [Interview Building Rocket] to talk about Java interview