0
A
回答
0
使用AspectJ您可以使用。圍繞()註釋:
@Aspect
public class TimedAnnotation {
@Around("execution(* *(..)) && @annotation(TimedMethod)")
public Object around(ProceedingJoinPoint point) throws Throwable {
long start = System.currentTimeMillis();
try {
Object p = point.proceed();
return p;
}
finally {
System.out.println(System.currentTimeMillis() - start);
}
}
}
你還是得把這個註釋爲每個方法:
@TimedMethod
public void doSomething() {
...
}
而且你需要添加的AspectJ到您的pom.xml:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
+0
它是否適用於此代碼:public void doSomething(){xyzclass.execute()}。我需要計算xyzclass中的doSomething和execute方法的時間。 – manikumar
+0
如果你控制xyzclass,你可以把@TimedMethod放在.execute()的地方。 –
相關問題
- 1. 尋找一種方法來計算openrefine中的時間流逝
- 2. 方法時間計算
- 3. 理論上如何計算某種方法的執行時間?
- 4. 計算的方法的執行時間
- 5. 使用時間或時間計時兩種算法(python)
- 6. 使用幾種方法計算運行時間分析
- 7. 如何爲每種方法計算該方法可能拋出的異常集,包括運行時異常?
- 8. 計算兩種方法之間的置信區間
- 9. 計算算法時間
- 10. Rails 4如何計算每種方法的總和
- 11. 計算每種方法的平均代碼行數
- 12. 時間的揹包算法
- 13. 在序言中計算算法時間
- 14. 一種計算列項目的方法
- 15. 測量C#中每種方法的編譯時間
- 16. jQuery中的每種方法
- 17. 計算對數算法的時間
- 18. 計算方法中有多少種方法?
- 19. 通過三種方法計算CCA
- 20. 每月計算工作時間。 MS Access
- 21. 另一種計算每個學生在MySQL中平均分數的方法?
- 22. 用mysql方法計算日期時間,使用rails方法
- 23. 包含計算的方法 - Rails 4
- 24. 不同的計算方法,包括presition
- 25. 方法和Thread.sleep之間的時間計算()
- 26. 計算空間和時間一致性的有效方法
- 27. 計算C中的時間
- 28. LINQ中的時間計算
- 29. 如何計算算法時間複雜
- 30. elasticsearch每小時直方圖計算
你看過AOP嗎? –
如果您只需要這樣一次,但並非永遠只需要看一次Java Profiler – Ralph
,請查看關於分析應用程序的以下技巧:https://www.infoq.com/articles/java-profiling-with-open-來源/ –