简体   繁体   中英

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?

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.

This garbage collector is not in use anymore and replaced by better garbage collectors.

The stop-the-world garbage collector really stopped the complete application (all threads) and cleaned up the heap.

When the garbage collector would take too long (which almost never happens) then an Error would be thrown.

Incomming traffic on network sockets is buffered for the time the collector runs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM