How can I disable Java garbage collector?

2019-01-17 15:04发布

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

8条回答
太酷不给撩
2楼-- · 2019-01-17 15:30

It sounds like you are trying to save time, but going about it the wrong way. The time saved in disabling garbage collection would be trivial (for a single task) compared to the time taken to launch and shutdown the java process. You might want to consider having a java process launch that you can ask multiple times to do the work you require if run-time performance is your goal.

查看更多
不美不萌又怎样
3楼-- · 2019-01-17 15:31

GC only kicks in when JVM is short on memory, so you either GC or die. Try turning on verbose GC and see if it actually takes significant amount of time.

java -verbose:gc
查看更多
登录 后发表回答