问题描述
这个问题是重复的
这是一个老问题,从那时起事情可能会发生很大变化。也没有说明一切。
是否可以更改GC线程优先级?我看到具有不同GC线程优先级的线程转储。如果我们无法改变它,那会发生什么?另外,据我所知,高频交易平台希望保持GC线程优先级很低,以便主线程在大多数时间运行,停止世界事件不会经常发生。
$ b
这个问题是重复的
这是一个老问题,从那时起事情可能会发生很大变化。也没有说明一切。
是否可以更改GC线程优先级?我看到具有不同GC线程优先级的线程转储。如果我们无法改变它,那会发生什么?另外,据我所知,高频交易平台希望保持GC线程优先级很低,以便主线程在大多数时间运行,停止世界事件不会经常发生。
b
长答案:
Java线程优先级要求为:
如果没有这两个,线程优先级将仅用作提示,并且不保证更高优先级的线程不会被优先级较低的线程占先。
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:
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).
这篇关于如何更改垃圾收集线程的优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!