Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-14189

Fix the annoying tomcat shutdown class reloading problem

    Details

    • Branch Version/s:
      6.0.x, 5.2.x, 5.1.x
    • Backported to Branch:
      Committed

      Description

      Tomcat has a feature to null out all classes' static fields to prevent memory leak. To do that, tomcat needs to reload the class by WebappClassLoader. The reload will force to rerun all classes' static initializing blocks. If the code inside the block call any service which is already out of service, then we will see a lot of exceptions. for example:
      java.lang.NullPointerException
      at com.liferay.util.SystemProperties.get(SystemProperties.java:50)
      at com.liferay.portal.upload.UploadServletRequestImpl.<clinit>(UploadServletRequestImpl.java:273)
      at sun.misc.Unsafe.ensureClassInitialized(Native Method)
      at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:25)
      at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:122)
      at java.lang.reflect.Field.acquireFieldAccessor(Field.java:918)
      at java.lang.reflect.Field.getFieldAccessor(Field.java:899)
      at java.lang.reflect.Field.set(Field.java:657)
      at org.apache.catalina.loader.WebappClassLoader.clearReferencesStaticFinal(WebappClassLoader.java:2034)
      at org.apache.catalina.loader.WebappClassLoader.clearReferences(WebappClassLoader.java:1894)
      at org.apache.catalina.loader.WebappClassLoader.stop(WebappClassLoader.java:1798)
      at org.apache.catalina.loader.WebappLoader.stop(WebappLoader.java:738)
      at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4812)
      at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:924)
      at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1319)
      at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1290)
      at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:323)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
      at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1086)
      at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
      at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:450)
      at org.apache.catalina.core.StandardService.stop(StandardService.java:587)
      at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
      at org.apache.catalina.startup.Catalina.stop(Catalina.java:648)
      at org.apache.catalina.startup.Catalina$CatalinaShutdownHook.run(Catalina.java:692)

      So basically we need to avoid calling service from classes' static initializing block.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shuyang.zhou Shuyang Zhou
              Reporter:
              shuyang.zhou Shuyang Zhou
              Participants of an Issue:
              Recent user:
              Esther Sanz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                9 years, 36 weeks, 1 day ago

                  Packages

                  Version Package
                  --Sprint - SP
                  6.1.0 CE RC1