计算Java启动成本 [英] Calculate Java start up cost
本文介绍了计算Java启动成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有一个程序,可以在其中打印运行 main 方法所需的时间.然而,当我在命令行上运行这个程序并计时时,它需要更长的时间.
I currently have a program in which I can print how long it takes to run the main method. When I run this program on command line and time it however, it takes considerably longer.
例如,
$ time java MyProgram "arg"
done by .004
real 0m0.105s
user 0m0.083s
sys 0m0.022s
我的问题是 - 是否可以在程序本身内计算 java 程序的启动成本?
My question is this- is it possible to calculate the start up cost of the java program within the program itself?
推荐答案
你可以把它作为你的 main 方法的第一行.java.lang.management.ManagementFactory.getRuntimeMXBean().getUptime()
You could put this as the first line in your main method.
java.lang.management.ManagementFactory.getRuntimeMXBean().getUptime()
这篇关于计算Java启动成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文