aop计算方法耗时
package necs.omms.common.aop; import lombok.extern.apachecommons.CommonsLog;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component; @Component
@Aspect
@CommonsLog
public class PerformanceMonitor {
private static Log log = LogFactory.getLog(PerformanceMonitor.class); /**
* A join point is in the controller layer if the method is
* modified by public and defined in a type in the
* com.shawn.service package or any sub-package under that
* and modified by public.execution(* com.baobaotao..*(..))l
*/
@Pointcut("execution( * necs.omms.controller..*(..))")
private void controllerLayer() {
} /**
* Monitor the elapsed time of method on controller layer, in
* order to detect performance problems as soon as possible.
* If elapsed time > 1 s, log it as an error. Otherwise, log it
* as an info.
*/
@Around("controllerLayer()")
public Object monitorElapsedTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// Timing the method in controller layer
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Object result = proceedingJoinPoint.proceed();
stopWatch.stop(); // Log the elapsed time
double elapsedTime = stopWatch.getTime() / 1000;
Signature signature = proceedingJoinPoint.getSignature();
String infoString = "[" + signature.toShortString() + "][Elapsed time: " + elapsedTime + " s]";
if (elapsedTime > 1) {
log.error(infoString + "[Note that it's time consuming!]");
} else {
log.info(infoString);
} // Return the result
return result;
} @Before(value = "controllerLayer()")
public void doBefore(){
System.out.println("-------------@BEFORE------------");
} }
aop计算方法耗时的更多相关文章
- AOP计算方法执行时长
AOP计算方法执行时长 依赖引入 <dependency> <groupId>org.springframework.boot</groupId> <arti ...
- springMVC Aspect AOP 接口耗时统计
在接口开发中,我们通常需要统计接口耗时,为后续接口性能做统计.在springMVC中可以用它的aop来记录日志. 1.在spring配置文件中开启AOP <!--*************** ...
- 利用spring AOP 和注解实现方法中查cache-我们到底能走多远系列(46)
主题:这份代码是开发中常见的代码,查询数据库某个主表的数据,为了提高性能,做一次缓存,每次调用时先拿缓存数据,有则直接返回,没有才向数据库查数据,降低数据库压力. public Merchant lo ...
- Spring Aop 应用实例与设计浅析
0.代码概述 代码说明:第一章中的代码为了突出模块化拆分的必要性,所以db采用了真实操作.下面代码中dao层使用了打印日志模拟插入db的方法,方便所有人运行demo. 1.项目代码地址:https:/ ...
- 实现自己的BeanFactory、AOP以及声明式事务
实现自己的BeanFactory 在使用spring时,我们很少用& ...
- Android Activity启动耗时统计方案
作者:林基宗 Activity的启动速度是很多开发者关心的问题,当页面跳转耗时过长时,App就会给人一种非常笨重的感觉.在遇到某个页面启动过慢的时候,开发的第一直觉一般是onCreate执行速度太慢了 ...
- JAVA提高八:动态代理技术
对于动态代理,学过AOP的应该都不会陌生,因为代理是实现AOP功能的核心和关键技术.那么今天我们将开始动态代理的学习: 一.引出动态代理 生活中代理应该是很常见的,比如你可以通过代理商去买电脑,也可以 ...
- TOP100summit:【分享实录】爆炸式增长的斗鱼架构平台的演进
本篇文章内容来自2016年TOP100summit斗鱼数据平台部总监吴瑞城的案例分享. 编辑:Cynthia 吴瑞诚:斗鱼数据平台部总监 曾先后就职于淘宝.一号店. 从0到1搭建公司大数据平台.平台规 ...
- 【springboot】给你一份Spring Boot知识清单
目录: 一.抛砖引玉:探索Spring IoC容器 1.1.Spring IoC容器 1.2.Spring容器扩展机制 二.夯实基础:JavaConfig与常见Annotation 2.1.JavaC ...
随机推荐
- LeetCode OJ:4Sum(4数字之和)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- JAVA代码反编译笔记
最近有个朋友说有个java弄的软件是从朋友处拿来的,由于进行了网卡地址绑定,不修改网卡地址无法使用,叫我看看有无办法破解,之前都很少玩这些东西,本着帮忙的心态,尝试了下,便有了一下的笔记内容. 1.使 ...
- 【python】imp模块的使用
是import在程序中的使用 [一]函数load_source imp.load_source(moduleName, sourceFile) 使用: abc = imp.load_source('d ...
- debounce与throttle区别
在2011年,Twitter网站曾爆出一个问题:在主页往下滚动时,页面会变得缓慢以致没有响应.John Resig发表了一篇文章< a blog post about the problem&g ...
- Arcgis for JS扩展GraphicLayer实现区域对象的聚类统计与展示
功能需求: 分省市统计并展示全国雨量站的数目与位置. 常规做法: 分省市雨量站的数目通过统计表的形式在页面端展示,位置根据XY坐标信息将雨量站标绘在图上. 优化做法: 去掉统计图的展示方式,直接将各省 ...
- 大白话讲解如何给github上项目贡献代码
本文献给对git很迷茫的新手,注意是新手,但至少会点基本操作,有点基本概念的新手,我不会从怎么用github和git是什么开始讲的.如果作为新手你看书又看不进去,原理又太复杂,又没有直接了当告诉我们怎 ...
- vue动态 设置类名
<div class="tab"> <navigator :class="currentTab=='mzfw'?'nav active': 'nav'& ...
- python学习之面向对象(下)
该篇主要是针对面向对象的细讲,包括类的多重继承,方法的重写,析构函数,回收机制进行讲解 #该类主要是讲述python面象对象的一些特征,包括继承,方法的重写,多态,垃圾回收 class person( ...
- 【抽时间 试验】hibernate集合映射inverse和cascade详解
http://www.cnblogs.com/amboyna/archive/2008/02/18/1072260.html
- ansible安装基本使用
备注使用yum (centos7) 1. 安装 yum install -y ansible 2. 免密登录(ssh,最好使用dns 解析) // create ssh key ssh-keyge ...