Technique or utility to minimize Java "warm-up" time?
"Warm-up" in Java is generally about two things:
(1): Lazy class loading: This can be work around by force it to load.
The easy way to do that is to send a fake message. You should be sure that the fake message will trigger all access to classes. For exmaple, if you send an empty message but your progrom will check if the message is empty and avoid doing certain things, then this will not work.
Another way to do it is to force class initialization by accessing that class when you program starts.
(2): The realtime optimization: At run time, Java VM will optimize some part of the code. This is the major reason why there is a warm-up time at all.
To ease this, you can sent bunch of fake (but look real) messages so that the optimization can finish before your user use it.
Another that you can help to ease this is to support inline such as using private and final as much as you can. the reason is that, the VM does not need to look up the inheritance table to see what method to actually be called.
Hope this helps.
Your problem is not class loading but "just in time" compilation.
Try -XX:CompileThreshold=1
That will force Java to compile everything the first time it runs it. It will slow down the startup of your code somewhat but not VM code (since that gets compiled when Java is installed). There is a bug open to allow Java to compile custom JARs in a similar way and save the result for later executions which would greatly reduce this overhead but there is no pressure to fix this bug any time soon.
A second option would be to send 5'000 fake messages to the app to "warm it up". Sell this as "making sure everything is set up correctly".
[EDIT] Some background info in precompiling classes: Class Data Sharing
You may want to try IBM's version of Java since here, you can add more classes to the shared pool: Overview of class data sharing
[EDIT2] To answer concerns raised by kittylyst: It's true that this will quickly fill up your code cache with methods that are used only once. And it might even make your whole app slower.
If you set it to a low value, the startup time of your application can become horribly slow. This is because the JIT optimization + running the compiled code is more expensive than running the code once in interpreted mode.
The main problem here is that the code is still compiled "just in time". As long as you can't run every method that you need at least once, the app will "hickup" for a few milliseconds every time it encounters something that hasn't been compiled before.
But if you have the RAM, your app is small or you can increase the size of the code cache and you don't mind the slow startup time, you can give this a try. Generally, the default setting is pretty good.
Just run a bunch of no-op messages through the system before it's opened for genuine customer traffic. 10k messages is the usual number.
For financial apps (e.g. FIX), this is often done by sending orders (at a price far away from last night's close, just in case) to the market before it opens. They'll all get rejected, but that doesn't matter.
If the protocol you're using is homebrew, then the next time you upgrade the libraries for it, add explicit support for a "WARMUP" or "TEST" or "SANITYCHECK" message type.
Of course, this likely won't compile up your application-logic-specific pathways, but in a decent messaging app, the part dealing with network traffic will almost certainly be the dominant part of the stack, so that doesn't matter.
If running in Hotspot's server mode on contemporary hardware (with 2 or more cores per CPU) and with latest version of JDK then following option can be used for speeding of warming up:
-server -XX:+TieredCompilation