Is it possible to change the priority of garbage Collector thread?

后端 未结 4 993
花落未央
花落未央 2021-01-07 12:41

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 prio

4条回答
  •  [愿得一人]
    2021-01-07 13:45

    When a thread is created it inherits the priority of the thread that created it. The priority of a thread can be adjusted by using

    public final void setPriority(int newPriority)

    The problem is a thread doesn't "run" the garbage collector. The garbage collector is run by the VM (when Java wants or is in "good mood .. :)" ).

    EDIT: The GC is not a thread but a method of the Runtime thread. You can change the priority of the Runtime thread but this will have no effect on the GC. The thread that calls the GC is a thread of the VM and is out side the scope of the API so you can't change its priority.

    So, I don't really think you can set its priority.

提交回复
热议问题