首页 文章详情

【面题精讲】今天来聊聊Java注解

Python涨薪研究所 | 384 2021-02-10 14:23 0 0 0
UniSMS (合一短信)

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;
}



—  —


一键三连「分享」、「点赞」和「在看」

技术干货与你天天见~


good-icon 0
favorite-icon 0
收藏
回复数量: 0
    暂无评论~~
    Ctrl+Enter