简体   繁体   English

如何在 jvm 应用程序中诱导长时间的完全 GC 暂停?

[英]How can I induce long full GC pause in jvm application?

I would like to induce long full GC pause in my jvm application.我想在我的 jvm 应用程序中诱导长时间的完全 GC 暂停。 Is there any command I can use?有什么我可以使用的命令吗? I would like to have more than 1 sec pauses.我希望有超过 1 秒的暂停。

To make full GCs longer (I assume that you are using Parallel Scavenge collector), I think you can try to:为了使完整的 GC 更长(我假设您正在使用 Parallel Scavenge 收集器),我认为您可以尝试:

  1. Disable young GCs before full GCs (-XX:-ScavengeBeforeFullGC).在完整 GC 之前禁用年轻 GC (-XX:-ScavengeBeforeFullGC)。 By doing this, full GCs are also responsible to collect the young generation and thus will take longer time than collecting old generation only.通过这样做,full GCs 也负责收集年轻代,因此比只收集老年代需要更长的时间。

  2. Reduce the size of young generation (eg, -XX:NewRatio or -Xmx).减少年轻代的大小(例如,-XX:NewRatio 或 -Xmx)。 So more objects would enter old generation instead of dying in the young generation.所以更多的对象会进入老年代而不是在年轻代中死去。 As a result, full GCs have more objects to collect and will be longer.因此,full GC 有更多的对象需要收集并且会更长。

  3. Allocate more long-lived objects (if you can modify the source code of your application).分配更多长寿命的对象(如果您可以修改应用程序的源代码)。 For example, try allocating long-lived and large arrays, because large arrays would be allocated in the old generation directly by JVM.例如,尝试分配长寿命和大 arrays,因为大 arrays 将直接由 JVM 在老年代分配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM