7 Replies Latest reply on Jan 31, 2017 7:00 AM by Martin Kouba

    Weld and Log4j2 problem

    Seto Kaiba Expert

      2017-01-28 13:18:27,626 Thread-1 ERROR Unable to register shutdown hook because JVM is shutting down. java.lang.IllegalStateException: Cannot add new shutdown hook as this is not started. Current state: STOPPED

        at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.addShutdownCallback(DefaultShutdownCallbackRegistry.java:113)

        at org.apache.logging.log4j.core.impl.Log4jContextFactory.addShutdownCallback(Log4jContextFactory.java:273)

        at org.apache.logging.log4j.core.LoggerContext.setUpShutdownHook(LoggerContext.java:256)

        at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:216)

        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:235)

        at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)

        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:167)

        at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:522)

        at org.jboss.logging.Log4j2Logger.<init>(Log4j2Logger.java:36)

        at org.jboss.logging.Log4j2LoggerProvider.getLogger(Log4j2LoggerProvider.java:30)

        at org.jboss.logging.Log4j2LoggerProvider.getLogger(Log4j2LoggerProvider.java:26)

        at org.jboss.logging.Logger.getLogger(Logger.java:2465)

        at org.jboss.logging.Logger$1.run(Logger.java:2565)

        at java.security.AccessController.doPrivileged(Native Method)

        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2529)

        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)

        at org.jboss.weld.logging.ContextLogger.<clinit>(ContextLogger.java:44)

        at org.jboss.weld.context.AbstractContext.destroy(AbstractContext.java:147)

        at org.jboss.weld.context.AbstractSharedContext.destroy(AbstractSharedContext.java:61)

        at org.jboss.weld.context.AbstractSharedContext.invalidate(AbstractSharedContext.java:56)

        at org.jboss.weld.bootstrap.WeldRuntime.shutdown(WeldRuntime.java:56)

        at org.jboss.weld.bootstrap.WeldBootstrap.shutdown(WeldBootstrap.java:113)

        at org.jboss.weld.environment.se.WeldContainer.shutdown(WeldContainer.java:267)

        at org.jboss.weld.environment.se.WeldContainer$ShutdownHook.run(WeldContainer.java:300)

       

       

      Weld SE container 0e65e92d-f825-4f57-a229-d860e5ef04f2 shut down by shutdown hook

      I started a cdi container. And press ctrl c to stop. And this error is thrown.

        • 1. Re: Weld and Log4j2 problem
          Martin Kouba Master

          Hi Seto,

          it looks like the DefaultShutdownCallbackRegistry (Log4j) attempts to register a Log4j-specific shutdown hook per a new logger instance (used by Weld, org.jboss.weld.logging.ContextLogger). But since this happens during a JVM shutdown, specifically during a Weld shutdown hook execution (Weld attempts to destroy all contexts correctly), DefaultShutdownCallbackRegistry throws IllegalStateException. This should not happen if you obtain any bean instance in your app - in this case, the logger should be initialized before the shutdown hook. If you don't use any bean in your app I think you can safely ignore this exception (no bean instance = empty contexts = no risk of incorrecly destroyed bean instances).

          • 2. Re: Weld and Log4j2 problem
            Seto Kaiba Expert

            What does it mean by obtain any bean instance? Of course there're managed beans in the app. It's with Java SE.

            This error is thrown when I use ctrl c to shutdown the app. Instead of normal main thread ended.

            • 3. Re: Weld and Log4j2 problem
              Martin Kouba Master

              What does it mean by obtain any bean instance?

              Do you get a bean instance and invoke a method upon it before stopping the app? I understand that you're using CTRL + C to shutdown the app - that's where a JVM shutdown hook gets into the game.

              • 4. Re: Weld and Log4j2 problem
                Seto Kaiba Expert

                The code is in the Kernel.java. And observes the ContainerInitialized event. And there's logic running in it.

                • 5. Re: Weld and Log4j2 problem
                  Martin Kouba Master

                  Ok, what's the Kernel class? Is the source code available? I can see the DeltaSpike code there as well. Do you really need to switch between CDI implementations? If not, I would recommend to get rid of DS ContextController and stick with Weld API (e.g. starting application context is completely unnecessary because in Weld it's always active).

                  • 6. Re: Weld and Log4j2 problem
                    Seto Kaiba Expert

                    No. It's not available. But I'll try if I can make a minimum reproduce project.

                    The basic logic in my Kernel is starting Deltaspike CDI container and inject Infinispan Cache and use Distributed Executor Service to run some tasks.

                    But if I remember correctly, the exception will be thrown even without Infinispan logic.

                    • 7. Re: Weld and Log4j2 problem
                      Martin Kouba Master

                      A simple reproducer would be great!