Home > Enterprise >  Will JVM choose the best GC type on its own during runtime?
Will JVM choose the best GC type on its own during runtime?

Time:12-04

JVM up from java 11 is using by Default G1.

If i wont change anything by myself, will JVM make any improvements by it own and change for example to Serial if my app will be lacking resources. Or whether app is in the container or not? Or i have to manage it by myself?

CodePudding user response:

No you will have to manage it yourself.

The default one Garbage First (G1) is a Solution that works good on most (almost all) cases. Finetuning or switching the GC is possible, but do so only with great care. You can easily make it worse, so only touch it if you really have a problem nailed down to the GC

CodePudding user response:

The Java Virtual Machine (JVM) does not automatically switch between garbage collectors based on the availability of resources. The default garbage collector for Java 11 and later versions is the G1 garbage collector, but this can be changed by specifying a different garbage collector when starting the JVM.

If your application is running low on resources, it is up to you to manage the garbage collection process and switch to a different garbage collector if necessary. For example, if your application is running low on memory, you may want to switch to the serial garbage collector, which is designed for applications with a small heap size.

To specify a different garbage collector when starting the JVM, you can use the -XX: Use command-line option. For example, to use the serial garbage collector, you can use the following command

java -XX: UseSerialGC MyApplication

You can also use the -XX: UseG1GC command-line option to specify that the G1 garbage collector should be used.

It's important to note that the choice of garbage collector can have a significant impact on the performance of your application, so it's important to carefully consider which garbage collector is best suited for your application's needs. You can use the JVM's garbage collection logs and other performance tools to monitor the behavior of the garbage collector and determine whether a different garbage collector would be more effective.

  • Related