如何禁用 Java 垃圾收集器? [英] How can I disable Java garbage collector?

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

问题描述

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

We have a PHP webapp that calls a Java binary to produce a PDF report (with JasperReports). The Java binary outputs the PDF to standard output and exits; the PHP then sends the PDF to browser. This Java command lasts about 3 to 6 seconds, and I think when it lasts 6 second it's because the GC kicks in. I would like to disable the GC 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..

推荐答案

没有办法完全禁用垃圾回收.垃圾收集仅在 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 的内存(默认为 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天全站免登陆