本文介绍了垃圾收集何时在java中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于java垃圾收集的文章,但是在搜索之后,我并不完全知道在java应用程序中运行垃圾收集时的情况(当应用程序重新启动或者它仍在运行时)。

解决方案

Garbage Collector 是dameon线。 Dameon线程在应用程序后面运行。它由JVM启动。当所有非dameon线程停止时,
线程停止。



JVM控制垃圾收集器;它决定何时运行垃圾收集器。 JVM在意识到内存不足时运行
垃圾收集器。 GC的行为可以通过将参数传递给 JVM 来进行调整。

可以从java程序中的
请求垃圾收集,但不能保证这个请求将由
处理jvm.Check




I knew that there are a lot of articles about java garbage collection but after searching I don't know exactly "when dose the garbage collection run in a java application?(when the application restart or while it still running)".

解决方案

Garbage Collector is a dameon thread. A dameon thread runs behind the application. It is started by JVM. Thethread stops when all non-dameon threads stop.

The JVM controls the Garbage Collector; it decides when to run the Garbage Collector. JVM runsthe Garbage Collector when it realizes that the memory is running low. The behavior of GC canbe tuned by passing parameters to JVM.

One can request the Garbage Collection to happen fromwithin the java program but there is no guarantee that this request will be taken care of byjvm.Check How to force garbage collection in Java?

Learn More ..

这篇关于垃圾收集何时在java中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 16:38