0
我有一個關於如何通過使用註釋的方法做了一次績效審計問題,AspectJ和Spring性能的方法審計基礎
基本上我有:
public class MyClass{
@TimeAudit
public myMethod(){
//do something
}
}
我只想在執行該方法所用的時間的某個地方記錄日誌(或僅將其打印在控制檯中)。我的問題是某個方面如何攔截該註釋,然後計算該方法花費的時間。
我該怎麼做? 澄清一點,我的問題: 我有註釋:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface TimeAudit {
}
我有我的方式:
@Aspect
@Component
public class PerformanceTimeExecutionAudit {
@Around("execution(* *(..)) && @annotation(timeAudit)")
public Object doLogTime(final ProceedingJoinPoint pjp, TimeAudit timeAudit) throws Throwable {
System.out.println("Start time..."+System.currentTimeMillis());
Object output = pjp.proceed();
System.out.println("End time..."+System.currentTimeMillis());
return output;
}
}
其他類:
@Repository
public class MyClass{
@Override
@TimeAudit
public void myMethod(){
//do something
}
}
,但該方面並不僅觸發該方法是我把@TimeAudit。 我做錯了什麼?
[Perf4J](http://www.infoq.com/articles/perf4j)。 – manish
謝謝你,它似乎做那個表現測量。但我想看看我能做到這一點。 – DanutClapa
您可以查看[Perf4J源代碼](https://github.com/perf4j/perf4j)。 '@ Profiled'註釋位於'aop'包中。這會觸發同樣包中的'ProfiledTimingAspect'。從這裏您可以按照代碼來了解實際測量和記錄的處理方式。 AspectJ配置在我鏈接到上面的頁面上。 – manish