我怎样才能禁用Java垃圾收集器? [英] How can I disable Java garbage collector?

查看:93
本文介绍了我怎样才能禁用Java垃圾收集器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个PHP webapp,它调用一个java二进制文件来生成pdf报告(带有jasperreport),java二进制outpus pdf到标准输出并退出,然后将php发送到浏览器。这个java命令持续大约3到6秒,我认为当它持续6秒钟时,这是因为GC启动了,所以我想禁用它,因为无论如何,当命令退出所有内存时返回。

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..

我想知道如何为Java 1.4.2和Java 1.6.0禁用它,因为我们目前正在测试两个JVM,以查看哪个更快执行。

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

推荐答案

没有办法完全禁用垃圾回收。垃圾收集只在JVM空间不足时运行,因此您可以为程序提供更多内存。将这些命令行选项添加到Java命令中

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

-Xmx256M -Xms256M

这给程序256Mb的ram(默认是64Mb)。垃圾收集对于默认大小的JVM不会花费3秒,因此您可能想要更仔细地调查程序正在执行的操作。 Yourkit profiler 对于确定需要很长时间的东西非常有用。

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.

这篇关于我怎样才能禁用Java垃圾收集器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆