我在主线程中有一个非常简单的scala异步方法,我试图看看执行需要多少才能使用相同的知识来分析我的实际API。
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
object ConcurrentTasks {
def main(args: Array[String]): Unit = {
println("starting task")
quickTask()
println("waiting for 30 secs")
Thread.sleep(30000)
}
private def quickTask(): Future[Int] = {
for {
x <- Future {
Thread.sleep(2000)
100
}
} yield {
println("finished computation " + x)
x
}
}
}
我进行分析的步骤
scala ConcurrentTasks.scala
微量
$ scala ConcurrentTasks.scala
starting task
waiting for 30 secs
finished computation 100
objc[26802]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home//bin/java (0x10899d4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x11041e4e0). One of the two will be used. Which one is undefined.
Profiler Agent: JNI OnLoad Initializing...
Profiler Agent: JNI OnLoad Initialized successfully
Profiler Agent: Waiting for connection on port 5140 (Protocol version: 15)
Profiler Agent: Established connection with the tool
Profiler Agent: Local accelerated session
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent: Redefining 100 classes at idx 0, out of total 106
Profiler Agent: Redefining 6 classes at idx 100, out of total 106
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent Warning: JVMTI classLoadHook: class name is null.
Profiler Agent: Connection with agent closed
Profiler Agent: Connection with agent closed
没关系,我正在使用java 1.8.0_151
。
我的主要问题是如何在jvisualVM中测量异步scala方法执行?