Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

query regarding garbage collector behavior

As I read in the Sun Memory management white paper:

When stop-the-world garbage collection is performed, execution of the application is completely
suspended during the collection

So if a request happens while the garbage collector is running then how is it handled by the application? If the garbage collector takes too long will the application throw an exception? I have not come across such an issue but wanted to know is this possible and what exception gets thrown?

like image 864
Jeets Avatar asked Jun 06 '26 13:06

Jeets


1 Answers

All (almost) Java garbage collectors has some sort of a Stop-the-world phase where all the Java threads are suspended waiting for a exclusive system operations to complete. This state is sometimes referred to as a safepoint.

The modern garbage collectors are concurrently running together with the applications threads, which means that the garbage collector perform its work at the same time as the application. During the garbage collector process there are phases where exclusive access memory is needed, the application threads goes into this safepoint state.

An exception is thrown if the garbage collector cannot recover enough memory to meet the application´s allocation demands.

One alternative to get rid of the stop-the-world garbage collections is to go for the Zing JVM with the C4 collector from Azul systems. The implementation has a low pause approach with no stop-the-world collections at all. Instead it is using a concurrent compacting approach with no stop-the-world phase.

like image 59
Robert Höglund Avatar answered Jun 08 '26 03:06

Robert Höglund