有没有办法告诉JVM在处理之前优化我的代码?

有没有办法告诉JVM在处理之前优化我的代码?

问题描述:

我有一个方法,第一次执行需要很长时间。但经过几次调用后,时间缩短了大约30倍。因此,为了使我的应用程序更快地响应用户交互,我使用一些关于应用程序初始化的示例数据预热此方法(5次)。但这会增加应用启动时间。

我读过,JVM可以优化并编译我的java代码到本机,从而加快速度。
我想知道 - 也许有一些方法可以明确告诉JVM我希望在启动应用程序时编译这个方法吗?

I have a method, which takes much time to execute first time. But after several invocations, it takes about 30 times less time. So, to make my application respond to user interaction faster, I "warm-up" this method (5 times) with some sample data on initialization of application. But this increases app start-up time.
I read, that JVM's can optimize and compile my java code to native, thus speeding things up. I wanted to know - maybe there is some way to explicitly tell JVM that I want this method to be compiled on startup of application?