如何更改垃圾收集线程的优先级? [英] How to change Garbage collection thread's priority?

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

问题描述

这个问题是重复的是否有可能改变垃圾收集器线程的优先级?



这是一个老问题,从那时起事情可能会发生很大变化。也没有说明一切。



是否可以更改GC线程优先级?我看到具有不同GC线程优先级的线程转储。如果我们无法改变它,那会发生什么?另外,据我所知,高频交易平台希望保持GC线程优先级很低,以便主线程在大多数时间运行,停止世界事件不会经常发生。

:不能使用线程优先级来避免GC干扰应用程序线程。


$ b

解决方案

b

长答案:



JVM和底层操作系统不遵守Java 线程优先级。这是一个众所周知的问题,例如,由RTSJ。


Java线程优先级要求为:


  • 支持Java优先级的专门设计的VM ,以及
  • 实时操作系统



如果没有这两个,线程优先级将仅用作提示,并且不保证更高优先级的线程不会被优先级较低的线程占先。



GC线程优先级由VM在创建GC线程时设置,不能从用户修改空间。 最后,高频交易的关键技术或避免GC停止世界暂停一般是小心的GC调整和选择一个合适的GC算法 - 这些都可以在comodity虚拟机(例如HotspotVM)中完成。


This question is duplicate of Is it possible to change the priority of garbage Collector thread?

It is an old question and things might have changed a lot since then. Also it doesn't clarifies everything.

Is it possible to change GC thread priority? I have seen thread dumps with different GC thread priority. How does that happen if we cannot change it? Also, I understand that High frequency trading platforms want to keep GC thread priority very low so that main threads run most of the time and "Stop the world" event doesn't occur very often.

解决方案

Short answer : thread priorities cannot be used to avoid GC interference with the application threads.

Long answer:

The Java thread priorities are not respected by the JVM and the underlying OS. This is a well known problem which was addressed e.g. by RTSJ.

Java thread priority requirements are:

  • specially designed VM that supports Java priorities, and
  • a real-time OS.

Without both of these, the thread priorities will be used only as a hint and there are no guarantees that a higher priority thread will not be preempted by a lower priority thread.

GC threads priorities are set by the VM when creating the GC threads and cannot be modified from the user space.

Finally, the key techniques for high frequency trading or avoiding the GC stop-the-world pauses in general are a careful GC tuning and selecting a proper GC algorithm - both of these can be done in a comodity VM (e.g. HotspotVM).

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

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