Error during hot deployment in JBoss

1.8k Views Asked by At

I am working in a Java/J2EE project with JBoss as an application server.

We build our war and do hot deployment in server using Jenkins.Sometimes, we get some Out of Memory error in JBoss.

I wonder if hot deployment is responsible for that. Also, would like to know if hot deployment has any pitfalls over normal manual start-stop deployment.

Can someone please provide some valuable inputs?

3

There are 3 best solutions below

0
On

I agree with the answers about adjusting your heap/permgen space, although its hard to be specific without more information about how much memory is allowed, what you are using etc.

Also, would like to know if hot deployment has any pitfalls over normal manual start-stop deployment.

When you manually start and stop the service between deployments you can be a little sloppy about cleaning up your web app - and no one will ever know.

When you hot deploy, the previous instance of your servlet context is destroyed. In order to reduce the frequency of OutOfMemory exceptions, you want to make sure that when this occurs, you clean up after yourself. Even though there is nothing you can do about classloader PermGen memory problems, you don't want to compound the problem by introducing additional memory leaks.

For example - if your war file starts any worker threads, these need to be stopped. If you bind an object in JNDI, the object should be unbound. If there are any open files, database connects etc. these should be closed.

If you are using a web framework like Spring - much of this is already taken care of. Spring registers a ServletContextListener which automatically stops the container when the servlet context is destroyed. However you would still need to make sure that any beans which create resources during init will clean up those resources during destroy.

If you are doing a hand-crafted servlet, then you would want to register an implementation of ServletContextListener in your web.xml file, and in the implementation of contextDestroyed clean up any resources.

BTW - you should include the exact OutOfMemory exception in your answer. If it says something like java.lang.OutOfMemoryError: PermGen space, then it's probably an issue of class instances and there is not much you can do. If it is java.lang.OutOfMemoryError: Java heap space then perhaps it's memory in your application that is not being cleaned up

0
On

Hot deployment does not clear up the previously loaded Class instances in Perm Gen. It loads the Class instances afresh. A little google pointed me back to SO What makes hot deployment a "hard problem"?

0
On

You should increase Heap Space specifically Perm Space

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-XX:MaxPermSize   set maximum Permanent generation size

You can set it in JAVA_OPTS in your jboss run.sh or run.bat like:

-Xms256m -Xmx1024m -XX:MaxPermSize=512m