we have a PHP webapp that calls a java binary to produce a pdf report (with jasperreport), the java binary outpus pdf to standart output and exits, the php then send the pdf to browser. This java command lasts about 3 to 6 seconds, I think when it lasts 6 second it's because the GC kicks in, so I would like to disable it because anyway when the command exits all memory is returned..
I would like to know how to disable it for Java 1.4.2 and for Java 1.6.0 because we are currently testing both JVM to see which performs faster..
Thanks
You can use the
-Xmx
option to set the maximum heap size; using a larger heap should prevent the VM from runnning out of memory and, thereby, requiring garbage collection so soon.Are you sure that it is garbage collection causing the slowdown? Have you run java with -verbose:gc to see what is happening?
You cannot disable garbage collection on the JVM. You could however look at tuning the garbage collector for better performance.
Java 11 comes with an no-op garbage collector.
It can be enabled by the
-XX:+UseEpsilonGC
option at JVM start.According to the JEP decription one of its goals is to make certain short-lived jobs more efficient, what might be you use case:
As everyone as said you can't disable GC in the JVM, which makes sense right, because if you could there'd be memory leaks due to java not having an explicit way for the developer to delete the heap data.
Do you have access to the source of this java binary? If so it might be worth analysing it and seeing if there's any bottle-necks which could be better written to cut down on GC activity. This could be done with most java profilers, like JProbe for example.
There is no way to disable garbage collection entirely. Garbage collection is only run when the JVM runs out of space, so you could give the program more memory. Add these command line options to the Java command
This gives the program 256Mb of ram (the default is 64Mb). Garbage collection will not take 3 seconds for a default size JVM though, so you might want to investigate more closely what the program is doing. Yourkit profiler is very useful for figuring out what is taking a long time.
To avoid garbage collector release a variable or property from any object, you must set this property (released by gc) as static in your class it was my solution.
Example:
private static String myProperty;