关于java:对线面试官Java注解

22次阅读

共计 1222 个字符,预计需要花费 4 分钟才能阅读完成。

public void send(String userName) {
  try {
    // qps 上报
    qps(params);
    long startTime = System.currentTimeMillis();

    // 构建上下文(模仿业务代码)ProcessContext processContext = new ProcessContext();
    UserModel userModel = new UserModel();
    userModel.setAge("22");
    userModel.setName(userName);
    //...

    // rt 上报
    long endTime = System.currentTimeMillis();
    rt(endTime - startTime);
  } catch (Exception e) {
    
    // 出错上报
    error(params);
  }
}

@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);

        // 办法执行开始工夫
        long startTime = System.currentTimeMillis();

        Object o = null;
        try {o = pjp.proceed();
        } catch (Exception e) {
            // 办法执行完结工夫
            long endTime = System.currentTimeMillis();

            tags.put("flag", "fail");
            monitor.avg("rt", tags, endTime - startTime);

            monitor.sum(functionName, "fail", 1);
            throw e;
        }

        // 办法执行完结工夫
        long endTime = System.currentTimeMillis();

        monitor.avg("rt", tags, endTime - startTime);

        if (null != o) {monitor.sum(functionName, "done", 1);
        }
        return o;
    }

文章以纯面试的角度去解说,所以有很多的细节是未铺垫的。

比如说反射、.java 文件 到 jvm 的过程、AOP 是什么等等等 … 这些在【Java3y】都有过具体的根本教程甚至电子书,我就不再详述了。

欢送关注我的微信公众号【面试造火箭】来聊聊 Java 面试

正文完
 0