snow8261
snow8261

Reputation: 1009

How to reduce the time of STOP-THE-WORLD in Java GC

We know that in Java a full GC can hang the JVM, which can also be called STOP-THE-WORLD. In many applications, hanging the JVM too long will cause a lot of problems. I want to know how to reduce the time of STOP-THE-WORLD in GC? What are the potential drawbacks caused by reducing the time of STOP-THE-WORLD? (not considering the JVM without stop-the-world behavior)

Upvotes: 3

Views: 1990

Answers (2)

KeineSorgen
KeineSorgen

Reputation: 51

If your objects live long time you can try to use DirectBuffers from New I/O package. Their creation and reclamation is more expensive than the creation and reclamation of heap-based non-direct buffers because direct buffers are managed using OS-specific native code. This added management cost makes direct buffers a poor choice for single-use or infrequently used cases.

Direct buffers are also outside the scope of Java’s garbage collector.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533492

There are many approaches

  • Create less garbage. A memory profiler will help.
  • Use less heap. A profiler can help reduce memory used.
  • Use off heap memory instead. There are number of libraries to store data off heap. e.g. Chronicle.
  • Use more memory and GCs will happen less often, possibly be less serious when they do. If you are using less than 32 GB of heap, this might be a quick win.
  • Use a fully concurrent collector like Azul's Zing. It doesn't have a STW collector.

I would start with the memory profiler to reduce garbage and heap usage, and tune the GC.

Upvotes: 2

Related Questions