weixin_39632397 2020-11-21 16:49
浏览 0

PAYARA-3344 Added System Property for Shutdown Grace Period

Initially the plan was to use domain.xml based configuration for the grace period setting. I looked into it but it turned out to be overly complicated due to module dependencies and access limitations. So I went for the simpler option using System property fish.payara.shutdowngrace instead. The period is given is milliseconds. E.g. -Dfish.payara.shutdowngrace=1000 for 1 second grace period.

After a first look into where to add the waiting it seamed most appropriate on the outermost level, like the PayaraMicroImpl#shutdown and equivalent methods. After deeper investigation on possible paths during shutdown I found that the common abstraction to server, micro and embedded that is called independent on how the shutdown was initiated should be the GlassFish abstraction. While there are a handful of implementations some of them are wrappers that delegate or extensions that extend. I think there are only 2 relevant implementations: GlassFishImpl and MicroGlassFish. As MicroGlassFish has access to GlassFishImpl it seamed a good way to share the code by making it a static method in GlassFishImpl. Surely no ideal place for common code but I could not find a better place in a common utility class. I believe that this modification includes embedded as embedded seams to wrap one of the other implementations.

In case of thread interruption or illegal value the grace period is zero and the shutdown continues as usual.

While testing the feature for payara micro I got exceptions logged during or after the grade period caused by further calls to stop/dispose as those were not synchronized for micro.

java
Cjava.lang.IllegalStateException: Already in STOPPING state.
    at fish.payara.micro.boot.runtime.MicroGlassFish.stop(MicroGlassFish.java:80)
    at fish.payara.micro.boot.runtime.MicroGlassFish.dispose(MicroGlassFish.java:96)
    at fish.payara.micro.impl.PayaraMicroImpl.bootStrap(PayaraMicroImpl.java:1045)
    at fish.payara.micro.impl.PayaraMicroImpl.main(PayaraMicroImpl.java:200)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at fish.payara.micro.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at fish.payara.micro.boot.loader.Launcher.launch(Launcher.java:107)
    at fish.payara.micro.boot.loader.Launcher.launch(Launcher.java:70)
    at fish.payara.micro.boot.PayaraMicroLauncher.main(PayaraMicroLauncher.java:79)
    at fish.payara.micro.PayaraMicro.main(PayaraMicro.java:397)
java.lang.NullPointerException
    at fish.payara.micro.boot.runtime.MicroGlassFish.stop(MicroGlassFish.java:85)
    at fish.payara.micro.boot.runtime.MicroGlassFish.dispose(MicroGlassFish.java:96)
    at fish.payara.micro.impl.PayaraMicroImpl$1.run(PayaraMicroImpl.java:1600)

Since the GlassFishImpl does synchronize these methods it seams logical that micro should do this as well. I applied it and tested it and it seams to prevent the problem.

As requested I also added a command line option for payara micro: --shutdowngrace <duration-ms>.

该提问来源于开源项目:payara/Payara

  • 写回答

6条回答 默认 最新

  • weixin_39632397 2020-11-21 16:49
    关注

    jenkins test please

    评论

报告相同问题?