How can I disable Java garbage collector?(如何禁用 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 垃圾收集器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何禁用 Java 垃圾收集器?


基础教程推荐
- 降序排序:Java Map 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01