From one article

System.runFinalization () creates a second stream "SecondaryFinalizer", which also calls finalize () for objects from the same queue, while the thread that caused System.runFinalization () waits until the Finalizer queue that is currently available ends.

I did not understand here, will it work in parallel? Or all the same, wait until the end of the first stream and continue, but then what is the use of it.

    1 answer 1

    Generally speaking, the implementation details of the runFinalization method are hidden in the VM implementation in use, and there are many different things that this method can do. For example, IKVM when calling runFinalization simply runs GC.WaitForPendingFinalizers() .

    The article you read probably says about Oracle JVM.

    The Secondary Finalizer will work in parallel with the main stream of finalization. In this case, the thread that caused runFinalization will sleep while the Secondary Finalizer is running.

    A new thread is done in order to provide all finalizers with the same stack size, runFinalization how much stack you have had to “spend” when calling runFinalization .


    For simplicity, you can assume that runFinalization simply runs all remaining finalizers in a row. This is almost indistinguishable from the observed behavior.

    • Yes, it says HotSpot VM - T. Kudaibergen