我试图理解如何为Kotlin的挂起函数创建@Around方面(例如,测量在此函数中花费的时间,或自定义的@Transactional方面):
@Timed("my-timer")
suspend fun test() {
println("before")
delay(50) // invokes ProceedingJoinPoint#proceed() before this line
println("after")
}由于此函数有一个挂起函数调用,因此@Around方面的前进函数将在调用delay()之前被调用。但很明显,我想测量在函数中花费的全部时间。
解决这个问题的正确方法是什么?也许我可以以某种方式订阅方法中的最后一个延续,或者像这样?
发布于 2019-01-03 11:03:26
我认为你可以很容易地解决你的问题,如果你想测量函数的执行时间,你可以使用内置的功能,比如:
val time = measureTimeMillis {
// yourSuperFunc()
}此外,您还可以使用measureNanoTime。要获得完整的参考信息,请查看here。
发布于 2020-02-17 01:49:20
这是由https://github.com/spring-projects/spring-framework/issues/22462跟踪的,很可能会在5.3中修复
同样的问题也发生在@Transactional上。
https://stackoverflow.com/questions/54015762
复制相似问题