0

I need to change a default garbage collector in Payara server(version 2025, jdk 21) docker image. I tried either preboot or postboot commands with configuration below, still not changing.

These are the config in postboot, adding ZGC garbage collector:

create-jvm-options --target=server-config -- "-XX\:+UseZGC" 
create-jvm-options --target=server-config -- "-XX\:+ZGenerational"

Then checking at inside container, the above config commands are included in domain.xml at /opt/payara/appserver/glassfish/domains/domain1/config.

Later I used these codes(from Dimania find which type of garbage collector is running) to check what type of GC is running:

try {
final List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();

for (GarbageCollectorMXBean gcMxBean : gcMxBeans) {
    logger.debug("Name: {}", () -> gcMxBean.getName());
    logger.debug("Obj: {}", () -> gcMxBean.getObjectName());
}

} catch (RuntimeException re) {
    throw re;
} catch (Exception exp) {
    throw new RuntimeException(exp);
}

The application reported me:

Name: G1 Young Generation
Obj: java.lang:type=GarbageCollector,name=G1 Young Generation
Name: G1 Concurrent GC
Obj: java.lang:type=GarbageCollector,name=G1 Concurrent GC
Name: G1 Old Generation
Obj: java.lang:type=GarbageCollector,name=G1 Old Generation

When I tried on local server (not container) and changed GC type directly(have to restart server) at domain.xml, result shown as follow:

Name: ZGC Minor Cycles
Obj: java.lang:type=GarbageCollector,name=ZGC Minor Cycles
Name: ZGC Minor Pauses
Obj: java.lang:type=GarbageCollector,name=ZGC Minor Pauses
Name: ZGC Major Cycles
Obj: java.lang:type=GarbageCollector,name=ZGC Major Cycles
Name: ZGC Major Pauses
Obj: java.lang:type=GarbageCollector,name=ZGC Major Pause

So any other steps I missed or have to add too, please kindly suggest.

1 Answer 1

0

Now I found the solution:

  1. have to use script - init_0_change_gc_webprofile.sh

  2. inside this script:

    1. use sed -i -z to find and replace. For example:

      sed -i -z 's|<jvm-options>-client</jvm-options>|<jvm-options>-server</jvm-options>\n<jvm-options>-XX:+UseShenandoahGC</jvm-options>'| ${PAYARA_DIR}/glassfish/domains/domain1/config/domain.xml

  3. use COPY in DockerFile. E.g.

    COPY init_0_change_gc_webprofile.sh ${SCRIPT_DIR}/

  4. build new image

  5. run your java app

    Note: you also can add other java-option such as Xmx, Xms, or fine tuning GC.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.