Skip to main content

Classloading issue when accessing class for the first time during JPA shutdown (Glassfish 3.1)

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
atomicknight
Offline
Joined: 2010-03-14

Hi, I've been running into an issue where an exception is thrown when undeploying an application on Glassfish 3.1 (b43). The stack trace looks like this:

java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [net.sf.ehcache.transaction.xa.processor.XARequestProcessor], because it has not yet been started, or was already stopped
        at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1410)
        at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1368)
        at net.sf.ehcache.CacheManager.shutdown(CacheManager.java:1174)
        at net.sf.ehcache.hibernate.EhCacheRegionFactory.stop(EhCacheRegionFactory.java:101)
        at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:958)
        at org.hibernate.ejb.EntityManagerFactoryImpl.close(EntityManagerFactoryImpl.java:127)
        at org.glassfish.persistence.jpa.JPADeployer.closeEMFs(JPADeployer.java:404)
        at org.glassfish.persistence.jpa.JPADeployer.event(JPADeployer.java:395)
        at org.glassfish.kernel.event.EventsImpl$1.run(EventsImpl.java:120)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)

Using the -XX:+TraceClassLoading flag shows that the XARequestProcessor class isn't loaded prior to being referenced from CacheManager#shutdown, meaning that the shutdown method is making a request for the class to be loaded. However, the WebappClassLoader instance is already stopped when that request is made, leading to this exception. It just so happens that this also prevents the WebappClassLoader instance from being garbage collected, which causes all the libraries in the web application to remain in memory indefinitely.

I've attached a simple test case that I've been using to reproduce this exception - simply deploying and undeploying the application gives the exception (note that you will need to add a JVM flag to get around the NPE obscuring the actual exception: -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false). I've also tried deploying/undeploying on Glassfish 3.0.1 - no exception is thrown there.

Does anyone have any experience with this? It looks like the lifecycle of the class loader isn't properly coordinated with the lifecycle of the JPA subsystem. Any ideas as to a workaround or a proper fix?

Thanks in advance.

AttachmentSize
glassfish-classloader.zip3.49 KB

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
slominskir
Offline
Joined: 2010-11-15

I encountered a similar (possibly the same) issue and created a topic here: http://www.java.net/forum/topic/glassfish/glassfish/undeploy-exception-u...

I'm not using EHCache though; all I've done is included Hibernate 3.6 with my web application (because I don't want to use EclipseLink).

mm110999
Offline
Joined: 2005-03-29

As the stack shows, GlassFish is trying to clean up by closing EMFs at
undeploy. By this time, the WebappClassLoader is already disposed. It is
strange for an app to initiate a new class load while being cleaned up
like done here by EhCacheRegionFactory. That said, this use case should
not be precluded. Please file a bug against jpa-connector or deployement
component of GlassFish to get this resolved.

Thanks,
Mitesh

On 5/23/2011 12:14 PM, forums@java.net wrote:
> Hi,
>
> I've been running into an issue where an exception is thrown when
> undeploying
> an application on Glassfish 3.1 (b43). The stack trace looks like this:
>
> java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to
> load
> resource [net.sf.ehcache.transaction.xa.processor.XARequestProcessor],
> because it has not yet been started, or was already stopped at
> org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1410)
>
> at
> org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1368)
>
> at net.sf.ehcache.CacheManager.shutdown(CacheManager.java:1174) at
> net.sf.ehcache.hibernate.EhCacheRegionFactory.stop(EhCacheRegionFactory.java:101)
>
> at
> org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:958)
> at
> org.hibernate.ejb.EntityManagerFactoryImpl.close(EntityManagerFactoryImpl.java:127)
>
> at
> org.glassfish.persistence.jpa.JPADeployer.closeEMFs(JPADeployer.java:404)
> at
> org.glassfish.persistence.jpa.JPADeployer.event(JPADeployer.java:395) at
> org.glassfish.kernel.event.EventsImpl$1.run(EventsImpl.java:120) at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at
>
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at
> java.util.concurrent.FutureTask.run(FutureTask.java:138) at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
>
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
>
> at java.lang.Thread.run(Thread.java:662)
> Using the -XX:+TraceClassLoading flag shows that the
> XARequestProcessor class
> isn't loaded prior to being referenced from CacheManager#shutdown,
> meaning
> that the shutdown method is making a request for the class to be loaded.
> However, the WebappClassLoader instance is already stopped when that
> request
> is made, leading to this exception. It just so happens that this also
> prevents the WebappClassLoader instance from being garbage collected,
> which
> causes all the libraries in the web application to remain in memory
> indefinitely.
>
> I've attached a simple test case that I've been using to reproduce this
> exception - simply deploying and undeploying the application gives the
> exception (note that you will need to add a JVM flag to get around the
> NPE
> obscuring the actual exception:
> -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false).
>
> I've also tried deploying/undeploying on Glassfish 3.0.1 - no
> exception is
> thrown there.
>
> Does anyone have any experience with this? It looks like the lifecycle
> of the
> class loader isn't properly coordinated with the lifecycle of the JPA
> subsystem. Any ideas?
>
> Thanks in advance.
>
>
> --
>
> [Message sent by forum member 'atomicknight']
>
> View Post: http://forums.java.net/node/805307
>
>
>

atomicknight
Offline
Joined: 2010-03-14

Thanks for the advice. I've filed a bug against deployment (there was no jpa-connector component in JIRA) here: http://java.net/jira/browse/GLASSFISH-16712