是否有可能改变垃圾收集器线程的优先级? [英] Is it possible to change the priority of garbage Collector thread?

查看:82
本文介绍了是否有可能改变垃圾收集器线程的优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java垃圾收集器以优先级1运行,因此无法保证如果调用System.gc()将实际执行。

有什么方法可以改变它的优先权吗?垃圾收集器是一个独立的线程(如汤姆霍廷在评论中,甚至不一定是一个单一的线程),它的优先级由Java虚拟机决定。这意味着你不能强制垃圾收集。调用 System.gc()会告诉运行时环境,now可能是运行GC的好时机,但垃圾收集实际上不能保证立即完成。

Java garbage collector runs with priority 1, due to which it is not guaranteed that System.gc() will actually execute if called.

Is there any way to change its priority? This shall enable me to run if I want.

解决方案

Garbage Collector is an independent thread (as reminded by Tom Hawtin in a comment, not even necessarily a single thread) and is on a priority which is decided by the Java Virtual Machine. This means you can't force garbage collection. Calling System.gc() tells the runtime environment that "now" might be a good time to run the GC but garbage collection is actually not guaranteed to be done immediately.

这篇关于是否有可能改变垃圾收集器线程的优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆