Exemplo n.º 1
0
 @Override
 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
     throws Exception {
   System.out.println(this.getClass().getSimpleName() + "---preHandle()...");
   long beginTime = System.currentTimeMillis();
   starTimeThreadLocal.set(beginTime);
   return super.preHandle(request, response, handler);
 }
Exemplo n.º 2
0
 @Override
 public void afterCompletion(
     HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
     throws Exception {
   System.out.println(this.getClass().getSimpleName() + "---afterCompletion()...");
   long endTime = System.currentTimeMillis();
   long beginTime = starTimeThreadLocal.get();
   long consumeTime = endTime - beginTime;
   System.out.println("consumeTime=" + consumeTime);
   super.afterCompletion(request, response, handler, ex);
 }
  @Override
  public void afterCompletion(
      HttpServletRequest _request, HttpServletResponse _response, Object _handler, Exception _ex)
      throws Exception {
    // TODO Auto-generated method stub

    long endTime = System.currentTimeMillis(); // 2、结束时间
    long beginTime = startTimeThreadLocal.get(); // 得到线程绑定的局部变量(开始时间)
    long consumeTime = endTime - beginTime; // 3、消耗的时间
    // System.out.println(consumeTime);
    if (consumeTime > 500) { // 此处认为处理时间超过500毫秒的请求为慢请求
      System.out.println(
          String.format("%s consume %d millis", _request.getRequestURI(), consumeTime));
    }
    log.info(_ex);
    super.afterCompletion(_request, _response, _handler, _ex);
  }
  @Override
  public boolean preHandle(
      HttpServletRequest _request, HttpServletResponse _response, Object _handler)
      throws Exception {
    // TODO Auto-generated method stub

    String uri = _request.getRequestURI();
    System.out.println(uri);

    long beginTime = System.currentTimeMillis(); // 1、开始时间
    startTimeThreadLocal.set(beginTime); // 线程绑定变量(该数据只有当前请求的线程可见)	
    if (_handler instanceof HandlerMethod) {
      log.info("--------------------------");
      HandlerMethod hm = (HandlerMethod) _handler;
      Method method = hm.getMethod();
      TypeVariable[] tvs = method.getTypeParameters();
      Type[] types = method.getGenericParameterTypes();
      log.info("--------------------------");
    }
    boolean rtn = super.preHandle(_request, _response, _handler);

    log.info(rtn);
    return rtn;
  }