简体   繁体   English

应用程序将永远不会执行垃圾收集时有什么条件?

[英]Is there any condition when application will never perform Garbage Collection?

Is there any condition when application will never perform Garbage Collection ? 应用程序将永远不会执行垃圾回收吗? Theoretically is it possible to have such application design ? 从理论上讲,可以进行这种应用程序设计吗?

Yes, there is. 就在这里。 Please read about memory leaks in Java. 请阅读有关Java中的内存泄漏的信息。 An example is described in Effective Java Item 6: Eliminate obsolete object references 有效Java项目6:消除过时的对象引用中描述了一个示例

Garbage collection happens on objects which are not referenced anymore in your application. 垃圾回收发生在您的应用程序中不再引用的对象上。

With Java 11, there is a way to never purposely perform garbage collection, by running your JVM with the newly introduced Epsilon GC , a garbage collector which handles memory allocation but never releases the allocated memory. 使用Java 11,可以通过使用新引入的Epsilon GC运行JVM来永远不执行垃圾回收,该垃圾回收器处理内存分配,但从不释放分配的内存。

There is at least one product in the market that implements high frequency trading using Java and jvm technology. 市场上至少有一种产品使用Java和jvm技术实现高频交易。

Obviously, an application that needs to react in microseconds can't afford a garbage collector to kick in and halt the system for arbitrary periods of time. 显然,需要微秒级响应的应用程序无法让垃圾收集器在任意时间段内启动并暂停系统。

In this case, the solution was to write the whole application to never create objects that turn into garbage. 在这种情况下,解决方案是编写整个应用程序,以永不创建会变成垃圾的对象。 For example, all input data is kept in fixed byte arrays (that are allocated once at start time) which are then used as buffers for all kinds of processing. 例如,所有输入数据都保存在固定的字节数组中(在开始时分配一次),然后将其用作各种处理的缓冲区。

Unless I am mistaken, you can listen to more details on the software engineering radio podcast. 除非我没有记错,否则您可以在软件工程广播播客上收听更多详细信息。 I think it should be this episode: http://www.se-radio.net/2016/04/se-radio-episode-255-monica-beckwith-on-java-garbage-collection/ 我认为应该是这一集: http : //www.se-radio.net/2016/04/se-radio-episode-255-monica-beckwith-on-java-garbage-collection/

Is there any condition when application will never perform Garbage Collection ? 应用程序将永远不会执行垃圾回收吗?

You can prevent the GC from running by having a Thread which doesn't reach a safe point. 您可以通过使用未达到安全要求的线程来阻止GC运行。

Unless you use a concurrent collector, the GC will only be performed when a memory region, eg when the Eden or Tenure spaces fill. 除非您使用并发收集器,否则仅在内存区域(例如,Eden或Tenure空间填充)时才执行GC。

If you make these large enough, and your garbage rate low enough, the GC won't run for long enough that you can either perform a GC overnight, in a maintenance window or restart the process. 如果您将它们做得足够大,而垃圾回收率足够低,则GC将无法运行足够长的时间,因此您无法在一夜之间,在维护窗口中执行GC或重新启动该过程。

Theoretically is it possible to have such application design? 从理论上讲,可以进行这种应用程序设计吗?

I have worked on applications which GC less than once per day (and some of them are restarted every day) 我曾经处理过每天少于一次GC的应用程序(其中一些每天都会重新启动)

For example, say you produce 300KB of garbage per second, or 1 GB per hour, with a 24 GB Eden size you can run for a whole day without a collection. 例如,假设您每秒产生300KB垃圾,或每小时产生1 GB垃圾,而Eden大小为24 GB,您可以整天运行而无需收集。

In reality, if you move most of your data off-heap eg Chronicle Map or Queue, you might find a 4 GB, can run for a day or even a week with a minor collection. 实际上,如果您将大部分数据移出堆外,例如Chronicle Map或Queue,则可能会发现有4 GB的空间,可以运行一天或什至一周,并且收集的数据很少。

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

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