How do I use the JAVA_OPTS environment variable?

JAVA_OPTS is the standard environment variable that some servers and other java apps append to the call that executes the java command. For example in tomcat if you define JAVA_OPTS=’-Xmx1024m’, the startup script will execute java org.apache.tomcat.Servert -Xmx1024m If you are running in Linux/OSX, you can set the JAVA_OPTS, right before you call the startup … Read more

Java for-loop optimization

It’s so easy to get fooled by hand-made microbenchmarks – you never know what they actually measure. That’s why there are special tools like JMH. But let’s analyze what happens to the primitive hand-made benchmark: static class HDouble { double value; } public static void main(String[] args) { primitive(); wrapper(); } public static void primitive() … Read more

Attach to already running JVM

Yes you can. 1) Inject a DLL in the process hosting the JVM (eg, java.exe, or javaw.exe, or iexplore.exe). A common injection technique is to use SetWindowsHookEx 2) In the DLL, get the module handle of the jvm.dll using GetModuleHandle 3) Get the address of the JNI_GetCreatedJavaVMs function, using GetProcAddress 4) Call the function and, … Read more