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

后端 未结 4 974
花落未央
花落未央 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:46

    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.

提交回复
热议问题