Class class loader on the issue of memory leaks

Since: http://blog.csdn.net/runanli/archive/2008/09/24/2972361.aspx

Wave background and technical personnel for the Guangdong Tobacco Tobacco December 10 memory overflow events of a wide range of technology and get some constructive suggestions and conclusions.

Which highlighted the:

"

About websphere console to restart the application, rather than restart the websphere, this time a static class can not be recovered, resulting in some classes can not be destroyed, occupied by the memory, but this memory can not be reused, can be said that the memory leak. Static class can not be destroyed, then the static class reference to an object can not be destroyed, so some bean not be normal recovery, in fact, occupied by the memory of these small objects are very few, most notably in reference to these classes do not destroy the cache, the cache the bulk of memory is occupied. If the system used a couple of days, and then someone in the console will restart the application, then the cache will not be destroyed, according to a waste into a lot of memory, so now we analyze the dump file, half of the memory cache is not destroyed by these non- occupied with the cache. In fact, BSP has a HttpServletContextListener, the listener be able to empty the cache when the application closed, but you can see from the dump file, this listener may not have time to call in the application closed.

Support for static class objects destroyed some issues need to study and solve Websphere this bug.

"

Therefore, we believe that the Bug is caused WAS: application to re-start the process of making some kind of Class MetatData describes itself can not be released from memory, while the tobacco system in LouShang some type of system for a large class of class Class static variables defined and static variables in these classes store a large number of objects. Over time, several times to restart the application to large amount of memory being used, leading to memory leaks.

Java static class for supplementary explanation: usually not allowed to declare a general class of static, only one internal class can. In an internal class provides static methods if you want to visit the premise, we will put this internal class is set to a static class. Then do not need an external instance of class and inner classes, but can directly call within the static method. Sample as follows:

view plainprint?
package com.test;
public class StaticCls (
public static void main (String [] args) (
OuterCls.InnerCls.test ();
)
)
class OuterCls (
public static class InnerCls (
public static void test () (
System.out.println ("InnerCls");
)
)
)
package com.test;
public class StaticCls (
public static void main (String [] args) (
OuterCls.InnerCls.test ();
)
)
class OuterCls (
public static class InnerCls (
public static void test () (
System.out.println ("InnerCls");
)
)
)

I believe in LouShang tobacco system application scenarios of this static class is rare, so the above-mentioned static class is not quite accurate, and should be corrected as follows: class static variables.

While the "static class" to "class static variable", but the above-mentioned Class MetatData class itself can not be described to be released from memory problems do exist. In the week of constant total December 14 issue of e-mail asking HeapAnalyzer have a very intuitive picture can explain the problem, the analysis of the actual production environment HeapDump document icons as follows:

One class org / loushang / bsp / organization / domain / support / Stru describes the properties of this class Stru itself:

a) One Size (304) is to describe its size class Stru

b) which No.Child (43) describes Stru class and methods for all variables used in reference to the class to the number of

c) which TotalSize (348,544,600) describes this Stru all references to the class and methods used to the size of the classes and methods + all references to the instance of the class used to the size of an object, all values larger. But only by the figure above listed TotalSize (348,544,600) does not directly state that causes abnormal memory usage from Stru

In a week of constant total e-mail reply, I said: "In the figure, there are two different addresses, different size class org / loushang / bsp / organization / domain / support / Stru it is some weird. General (in the normal class loader to run the course) will only exist in memory in the current class description of a Class. "

At that time I just feel more strange: Why are there two in memory of the Class Stru class description? But did not pay sufficient attention: that it is a serious problem.

Constant in subsequent weeks, the overall message that:

"The test of our technical staff, found that two class problem is a Websphere the bug, re-start the ear after application of static variables and object references will not be released. Every reboot one more class time on the line."

Guards then the total message on December 19 that the message here:

"By restarting the console does not release the static variable. Was the intention to do so, or whether this conclusion is incorrect?"

Thus, the formation of a proposition:

In the WAS server, if the restart J2EE application (not restart the WAS server), certain types of classes can not be recovered from memory. Restart application may result in multiple memory leak?

This is not WAS a Bug?

Question: Application restart, resulting in memory leak?
To address this question, we can turn to Google to get some clues, we can search key words: OutOfMemoryError redeploy, restart the application to obtain information on a wealth of information leading to memory leaks.

We have a few more classics to share with you:

1, the repeated deployment of JBOSS start the application server will result in OutOfMemory
URL: http://jira.jboss.com/jira/browse/JBAS-2299
Description: OutOfMemory error when repetatively deploying and undeploying with 10 minute interval
Remains unresolved

2, why repeat the deployment of applications will continue to lead to increased use of Tomcat memory?
URL: http://wiki.apache.org/tomcat/FAQ/Deployment
Description: Why does the memory usage increase when I redeploy a web application?
Remains unresolved

3, SUN JDK + Tomcat 5.5.20 to run the service when a problem, restart the application, the server will hang after a few days and report to java.lang.OutOfMemoryError: PermGen space exception.
URL: http://www.javaeye.com/topic/80620
Description: The inference may be caused due SUN JDK's BUG is loaded into the SUN JVM Perm region Class can not be recycled lead to memory leaks, recommend using IBM JDK or BEA JRokit virtual machine to solve the problem. (My comment: Actually, not a JVM BUG result)

4, that is the Spring leading to OutOfMemory, start the great debate
URL: http://forum.springframework.org/showthread.php?t=21383&highlight=cglib+cache&page=4

5, some considered to be caused by SUN JDK Bug
URL: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4957990
Description: In 2003, when there is a bug report to the sun, but until now, this bug has not close! This bug was added in the sentence reviews: "A bug this critical is open since 2003? Absolutely shameful." Do you think that SUN BUG indeed some of this disgrace, in fact, do not think this is a JVM SUN BUG itself caused, must be applied BUG itself caused.

Really different opinions, there is no exact answer.

But we can be more common this problem, look not because of WAS application server, JDK / JRE, Tomcat, Spring, Hibernate and other middleware Bug caused the following to describe what we would guess:

1, for the Class of the MetaData class description is in the SUN JDK in memory PermGen space dedicated to storage (PermGen space full name is the Permanent Generation space, is the permanent preservation areas of memory, this memory is stored mainly by JVM Class and Meta information, Class Loader time being will be put PermGen space, it and store class instance (Instance) of the Heap regional differences), but the default PermGen space is relatively small for the 4M. So once the application to restart and there is duplication of the same Class loading conditions, can easily lead to PermGen overflow, which directly led to "java.lang.OutOfMemoryError: PermGen space" appear.
For using IBM JDK or BEA JRokit JVM seems to solve the problem, in fact, does not fundamentally resolve the Class class to repeat loading problem. Only in the IBM JDK or BEA JRokit JVM contains no specific PermGen space to store Class class description, but sharing space with the JVM Heap, so repeat the loaded Class does not immediately lead to memory overflow. But the cumulative, the problem will still be apparent, as the general issue of Tobacco.

2, why the same question in different J2EE platforms, different J2EE framework, have also experienced different JDK? Does not seem to result from these middleware Bug, Are these different vendors, developers of the code there is the same Bug?

Really speak louder than words, we use the facts speak for it: we try to develop some scenarios to reproduce the problem.

Reproduce the problem restart the application to determine the Class class to repeat after loading problems?

Class is repeated for the loading of the problem, all the JVM Profiling the market can not be effective diagnostic tools to track and debug. The only possible way: that is a problem using the IBM JVM running the application, through the JVM interface or Unix environment, kill -3 <Java_PID> way to generate the current JVM HeapDump JVM file, thus we can use the IBM HeapAnalyzer tools to analyze whether there is duplication of Class class loading problem.

To simplify the process generate Java HeapDump, we specifically developed for JSP pages generated HeapDump documents to facilitate our Windows platform testing and validation.

dump.jsp

view plainprint?
<! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" " http://www.w3.org/TR/html4/loose.dtd ">
< % @ page language = "Java" contentType = "text / html; charset = GB18030" pageEncoding = "GB18030"%>
<html> <head>
<title> dump </ title>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030"> </ head>
<body>
<h2> produce HeapDump and JavaCore </ h2>
<% String heapdumpCmd = request.getParameter ("heapdump");
if (heapdumpCmd! = null) com.ibm.jvm.Dump.HeapDump ();
String javacoreCmd = request.getParameter ("javacore");
if (javacoreCmd! = null) com.ibm.jvm.Dump.JavaDump ();
String gcCmd = request.getParameter ("gc");
if (gcCmd! = null) System.gc ();%>
<form action="dump.jsp">
<input type="submit" name="gc" value="GarbageCollection">
<input type="submit" name="heapdump" value="CreateHeapDump">
<input type="submit" name="javacore" value="CreateJavaCore"> </ form>
</ Body>
</ Html>
<! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN" " http://www.w3.org/TR/html4/loose.dtd ">
< % @ page language = "Java" contentType = "text / html; charset = GB18030" pageEncoding = "GB18030"%>
<html> <head>
<title> dump </ title>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030"> </ head>
<body>
<h2> produce HeapDump and JavaCore </ h2>
<% String heapdumpCmd = request.getParameter ("heapdump");
if (heapdumpCmd! = null) com.ibm.jvm.Dump.HeapDump ();
String javacoreCmd = request.getParameter ("javacore");
if (javacoreCmd! = null) com.ibm.jvm.Dump.JavaDump ();
String gcCmd = request.getParameter ("gc");
if (gcCmd! = null) System.gc ();%>
<form action="dump.jsp">
<input type="submit" name="gc" value="GarbageCollection">
<input type="submit" name="heapdump" value="CreateHeapDump">
<input type="submit" name="javacore" value="CreateJavaCore"> </ form>
</ Body>
</ Html>

Try to prepare the sample reproduce the problem repeated loading Class

Development Center under the wave and the wave of the tobacco research center in the feedback has been considered a static variable used as class leading Class can not be released to appear Class repeated loading problem. To this end we simulate the following code:

ClassLoadBugServlet.java

view plainprint?
public class ClassLoadBugServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet (
private static byte [] testByteArray = new byte [2024000];
public ClassLoadBugServlet () (super ();)
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
perform (request, response);
)
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
perform (request, response);
)
private void perform (HttpServletRequest request, HttpServletResponse response) throws IOException (
StaticClass sc = new StaticClass ();
response.getOutputStream (). print (sc.test ());
System.out.println (sc.test ());
)
)
public class ClassLoadBugServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet (
private static byte [] testByteArray = new byte [2024000];
public ClassLoadBugServlet () (super ();)
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
perform (request, response);
)
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
perform (request, response);
)
private void perform (HttpServletRequest request, HttpServletResponse response) throws IOException (
StaticClass sc = new StaticClass ();
response.getOutputStream (). print (sc.test ());
System.out.println (sc.test ());
)
)

StaticClass.java

view plainprint?
public class StaticClass (
private static byte [] testByteArray = new byte [2024000];
public String test () (return "Test Class Loader";)
)
public class StaticClass (
private static byte [] testByteArray = new byte [2024000];
public String test () (return "Test Class Loader";)
)

Use the above code, we deployed to the WAS for the corresponding test, repeat run, restart the application dozens of times, using the above dump.jsp produce what we need JVM HeapDump, and then use the IBM HeapAnalyzer analyzed, and no we mention above to the Class repeat loading problem.

Experiment is a win.

Class repeated loading problem can be reproduced

Wave of software based wave of tobacco and LouShang v3 v3 core of the system in the Spring Framework platform, and there are pages in the Internet web site reflect the existence of Class Spring platform repeated loading problem http://forum.springframework.org/showthread.php? t = 21383 & highlight = cglib + cache & page = 4

To this end we transform the above sample to use Spring Framework to load StaticClass, to further verify the existence of Class repeated loading problem.

ClassLoaderTestServlet.java

view plainprint?
public class ClassLoaderTestServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet (
public ClassLoaderTestServlet () (super ();)
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
(Perform (request, response);)
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
(Perform (request, response);)
private void perform (HttpServletRequest request, HttpServletResponse response) throws IOException (
StaticClass sc = (StaticClass) getClassPathApplicationContext (). GetBean ("staticClass");
response.getOutputStream (). print (sc.test ());
System.out.println (sc.test ());
)
private ApplicationContext getWebApplicationContext ()
(WebApplicationContext wac = null;
wac = (WebApplicationContext) getServletContext (). getAttribute (WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
return wac;
)
private ApplicationContext getClassPathApplicationContext ()
(ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext ("spring / serviceContext.xml");
return context;
)
)
public
class ClassLoaderTestServlet extends javax.servlet.http.HttpServlet
implements javax.servlet.Servlet (
public ClassLoaderTestServlet () (super ();)
protected void doGet (HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
(Perform (request, response);)
protected void doPost (HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
(Perform (request, response);)
private void perform (HttpServletRequest request,
HttpServletResponse response) throws IOException (
StaticClass sc = (StaticClass)
getClassPathApplicationContext (). getBean ("staticClass");
response.getOutputStream (). print (sc.test ());
System.out.println (sc.test ());
)
private ApplicationContext getWebApplicationContext ()
(WebApplicationContext wac = null;
wac =
(WebApplicationContext) getServletContext (). GetAttribute (WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
return wac;
)
private ApplicationContext getClassPathApplicationContext ()
(ClassPathXmlApplicationContext context = new
ClassPathXmlApplicationContext ("spring / serviceContext.xml");
return context;
)
)

spring / serviceContext.xml

view plainprint?
<? Xml version = "1.0" encoding = "GBK"?>
<Beans xmlns = " http://www.springframework.org/schema/beans "
xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance "
xmlns: AOP = " http://www.springframework.org/schema/aop "
xsi: schemaLocation = " http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd "
default-autowire = "byName" default-lazy-init = "true">
<bean/>
</ Beans>
<? Xml
version = "1.0" encoding = "GBK"?>
<Beans xmlns = " http://www.springframework.org/schema/beans "
xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance "
xmlns: AOP = " http://www.springframework.org/schema/aop "
xsi: schemaLocation = " http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd "
default-autowire = "byName" default-lazy-init = "true">
<bean/>
</ Beans>

The same way we use the above code, deploy to WAS for the corresponding test, repeat run, restart the application dozens of times, using the above dump.jsp produce what we need JVM HeapDump, and then use the IBM HeapAnalyzer analysis, culminating in our Repeat the above-mentioned Class loading problem.

Is Spring the Bug class has led to repeated load Class? Unthinkable?

In order to locate there in the Spring Class of repeated loading, we need to elaborate on the JVM memory garbage collection, and load the basic principles of class Class.

JVM GC overview of garbage collection
JVM GC Java Virtual Machine that is the JVM garbage collection mechanism for the release of those objects are no longer using the memory. JVM Java language does not require a GC, GC did not provide for how they work. However, the JVM have used GC, and most use a similar algorithm GC memory management and implementation of collection operations.

The purpose is to clear the garbage collection of objects no longer in use, and now most of the JVM traverse through the use of object references the way (to determine whether the object referenced by activities) to determine whether the collection of the (garbage) objects. Traverse object references starting from the root thread object, along the entire object graph on each object reference links, can be reached recursively determine the (reachable) objects. If an object can not reach the root of the thread object reference, will be collected as garbage.

The basic mechanism of Class class loading such as the IBM WAS J2EE application server to allow the preparation of a number of J2EE application EAR / WAR deployment to the same J2EE application server. If one changes one J2EE application, and we long for this EAR / WAR to be updated, re-deployment, start the EAR / WAR application, does not need to re-start the deployment where the application server, which does not affect the deployment of the same application server other applications running.

The realization of this function is mainly due to WAS and other J2EE server, for different application EAR / WAR ClassLoader provides a different class loader, the ClassLoader used to load their own Class class, Guer different EAR / WAR application between will not affect each other. ClassLoader itself is simply a standard Java Class (provided by the J2EE container), but its special in just for the load in / WEB-INF/classes or JAR file in the Class class. Under normal circumstances, when you stop the application, this application's ClassLoader EAR J2EE application server will be discarded as waste, Guer all this EAR ClassLoader class loader that loaded the class will be discarded as garbage, finally recovered for JVM GC.

The J2EE application server in all there different levels of ClassLoader, is our WAS application server as an example (please refer to the other server ClassLoader "Tomcat and Websphere class loading mechanism"):

Websphere class loading mechanism

Java application running, in the Class of implementation and be visit, it must pass class loader loads to be effective, JVM class loader is part of the code which is responsible for the virtual Machine JVM to locate and load all Java classes and local lib library. Class loader effects of different configurations to the application deployment to application server run-time behavior. JVM and WebSphere Application Server provides a variety of different class loader configuration, forming a hierarchical structure with parent-child relationship.

WebSphere class loader in the hierarchy icon

As shown above, WebSphere in the class loader to be organized into a top-down hierarchy, the top is the system environment JVM, the lowest level is a specific application, parent-child relationship between the upper and lower layers.

a) JVM Class loader: at the top of the hierarchy, it is the class loader hierarchy of the root, so it has no parent class loader. This class is responsible for load JVM class loader, JVM extension classes, and defined in the classpath environment variable on all the Java classes.

b) WebSphere Extensions Class loader: WebSphere Extension class loader, which loads the WebSphere some of the runtime class, the resource adapter classes and so on.

c) WebSphere lib / app Class loader: WebSphere server class loader, which loads the WebSphere installation directory under $ (WAS_HOME) / lib / app path class. Version in WAS v4, WAS use this path is shared between all applications jar package. Starting from the WAS v5, shared library function provides a better way, therefore, the class loader for a number of existing systems compatible.

d) WebSphere "server" Class loader: WebSphere Application Server class loader. It is defined in the server is shared between all applications of classes. WAS v5 in with the concept of shared libraries, you can define multiple application servers for the shared library associated with the class loader, they define the order in accordance with the formation of parent-child relationship.

e) Application Module Class Loader: application class loader, in the last layer of the hierarchy, is used to load J2EE applications. According to the application's class loading strategy of different Web modules can also define your own class loader.

On the WebSphere class loader hierarchy, for the following description may be more helpful to find and understand the class loading process:

a) Each class loader is responsible for the definition of the class in its own path to find and load classes.

b) a child class loader can delegate to its parent class loader to find and load the class, a class loading request from the child class loader will be sent to the parent class loader, but never from the parent sent to the child class loader class loader.

c) Once a class is successfully loaded, JVM will cache the class until the end of its life cycle, and it and the corresponding class loader associated with, which means that different class loader (or the lower grade level between) can be loaded with the same name of the class.

d) If a loaded class depends on one or several classes, these being dependent on the class must exist in this type of class loader search path, or the parent class loader search path.

If a class loader and all of its parent class loader can not find the class, the system will throw ClassNotFoundExecption NoClassDefFoundError exception or error.

JVM GC garbage collection and class loader ClassLoader subtle relationship between the existence of the application, if you like the following code:

view plainprint?
private void x1 () (
for (;;) (
List c = new ArrayList ();
)
)
private void x1 () (
for (;;) (
List c = new ArrayList ();
)
)

This code will run repeatedly to apply new ArrayList object memory space, but this code does not cause memory leaks OutOfMemory phenomenon. Because of the continuing application of a new ArrayList object will be immediately discarded as garbage object eventually recovered in the JVM GC process, and release the memory space occupied by the Heap, so we can continue to apply to the new object the required memory space.

Now we Servlet, for example, demonstrated under normal operating conditions the following code in memory usage

view plainprint?
public class Servlet1 extends HttpServlet (
private static final String STATICNAME = "Simple";
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
)
)
public class Servlet1 extends HttpServlet (
private static final String STATICNAME = "Simple";
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
)
)

When this Serlvet1 class is loaded into memory at run time, the following objects and classes Class object will exist in memory, interconnected relationships are shown below (the core of several classes and objects):

The yellow box is identified by the application ClassLoader class loader (AppClassLoader) load of classes and the corresponding object class instance, the other to the green box are identified. One Graphic (simplified) of the J2EE container object Container reference point to the end J2EE applications to create the application class loader AppClassLoader object, at the same time reference also points to the application class loader created Serlvet1 loaded AppClassLoader instance object. When the external HTTP requests to this Servlet1, the container will call Servlet1 Container object instance doGet () method to provide services.

A few of them should draw attention to:

a) which are Class Servlet1 STATICNAME class all its own, not part of Servlet1 class instance object.

b) an instance of an object which contains the reference point Servlet1 Servlet1.class class itself.

c) Each Class class contains a reference point to load the Class class class loader AppClassLoader object.

d) At the same time each class loader object contains a reference point AppClassLoader classes loaded by Class

Icon from the above, we can clear that, if other than AppClassLoader class loader loaded the object refers to any object loaded by the AppClassLoader, then loaded by the AppClassLoader any Class (including AppClassLoader itself) will not be garbage collection. This conclusion is very important, which receive the above we describe the phenomenon of memory leaks Class fundamental reasons, followed by we will explain this phenomenon is Ruhe was triggered.

Under normal circumstances, if the application is deployed above unloaded or stopped, then the Container object to be associated with the application of any of classes and objects (such as Servlet1 instance of an object, AppClassLoader class loader instance) Disconnect the reference correlation, so these and stopped all application-related classes and class instances will be discarded as waste and JVM for recovery of memory.

As shown above, Servlet1 application-related classes, objects, class loader objects, etc. All and all the root thread object has no association, which will eventually be JVM for garbage collection.

Now we come to demonstrate a sample of non-normal circumstances, it is this "abnormal" result in the application of all the Class class can not be destroyed from the memory correctly. Here we introduced the original sample Servlet1 a special Class class and its instances: Level, rewrite the sample code as follows:

view plainprint?
package com.test;
import java.io. *;
import java.util.logging .*;
import javax.servlet .*;
import javax.servlet.http .*;
public class LeakServlet extends HttpServlet (
private static final String STATICNAME = "This leaks!";
private static final Level CUSTOMLEVEL = new Level ("test", 550) (); / / anon class!
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
Logger.getLogger ("test"). Log (CUSTOMLEVEL, "doGet called");
)
)
package com.test;
import java.io. *;
import java.util.logging .*;
import javax.servlet .*;
import javax.servlet.http .*;
public class LeakServlet extends HttpServlet (
private static final String STATICNAME = "This leaks!";
private static final Level CUSTOMLEVEL = new Level ("test", 550) (); / / anon class!
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
Logger.getLogger ("test"). Log (CUSTOMLEVEL, "doGet called");
)
)

Note that an anonymous type which CUSTOMLEVEL is an instance of an object class, the class constructor for Level property protected, can not be directly constructed, we must create a new class of new Level ("test", 550) (), to form LeakServlet of built-in class, the final compilation will generate LeakServlet $ 1.class

When this LeakServlet.class class is loaded into memory at run time, the following objects and classes Class object will exist in memory, each icon associated with the following (the core of several classes and objects):

This icon appears in your unexpected scene: System Level class instance using a class static variable ArrayList to hold all created instances of all types of Level objects, we can JDK Level class source code to verify:

view plainprint?
public class Level implements java.io.Serializable (
private static java.util.ArrayList known = new java.util.ArrayList ();
... ...
protected Level (String name, int value) (
this (name, value, null);
)
protected Level (String name, int value, String resourceBundleName) (
if (name == null) (
throw new NullPointerException ();
)
this.name = name;
this.value = value;
this.resourceBundleName = resourceBundleName;
synchronized (Level.class) (known.add (this);)
)
... ...
)
public class Level implements java.io.Serializable (
private static java.util.ArrayList known = new java.util.ArrayList ();
... ...
protected Level (String name, int value) (
this (name, value, null);
)
protected Level (String name, int value, String resourceBundleName) (
if (name == null) (
throw new NullPointerException ();
)
this.name = name;
this.value = value;
this.resourceBundleName = resourceBundleName;
synchronized (Level.class) (known.add (this);)
)
... ...
)

When the application is unloaded or stopped, then the JVM GC can do those things?

Serious has happened, in all classes and instances of objects in the instance of the object is only LeakServlet JVM GC in order to be recycled in any other class loaded by the AppClassLoader JVM GC can not be deleted from the memory of the destruction.

Because the Level class is WebSphere Application Server JRE core system classes, present in the core library core.jar file in the JRE, is a top class JVM ClassLoader loader to be loaded, that is not part of the class Level.class application class loader AppClassLoader.

When the application is unloaded or stopped, Level.class JVM is loaded by the system, so Level.class will not be recovered, then it references CUSTOMLEVEL instance variables and their corresponding class LeakServlet $ 1 will not be recovered resulting AppClassLoader JVM object can not be recovered, which ultimately lead to the application of all the Class class (Class MetaData attribute descriptions) can not be carried out JVM memory as garbage collection.

When the application is restarted, will be the newly created AppClassLoader to reload all of the Class class, so at this time in memory, there exists a class of multisection copies of the same Class.

This form of the notorious class loader ClassLoader memory leak problem.

Serious warning: If there is any application other than from a reference cited by the J2EE application itself class loader loads the class and class instance object, then ClassLoader class loader memory leak problem arises.

ClassLoader class loader memory leak problem of positioning is as described above Classloader memory leak because of class loader repeatedly to start and stop applications lead to multiple load Class and object reference as the relationship between system level, leading to the class previously created can not be recovered, leading to memory leaks.

ClassLoader class load positioning the root of the memory leak is still very difficult, because any existing JVM Profiling tools can not ClassLoader perspective to analyze the current memory of the existence of Class class. Currently we can only generate JVM Heapdump way to identify whether there ClassLoader class loader memory leak, then the above class loader ClassLoader memory leak generating mechanism for troubleshooting problems that may occur, ultimately solve the problem.

Seems to concentrate in JDK6 tool provides the tools to locate the problem. Please refer to http://blogs.sun.com/fkieviet/entry/how_to_fix_the_dreaded

To simplify troubleshooting and positioning applications, you may ClassLoader memory leak in the process of class loading, for which we have listed a number of class loading can cause Classloader memory leak code and components: (We are not here to roll out coverage on the following components of the root cause memory leaks, as our work on it! haha)

a) application or use of the components used java.util.logging.Level that you have to pay attention.

b) If you use such as DBCP and other development on the basis of DriverManager API database connection pool component, if the underlying design of ill-considered, can easily lead to class loading Classloader memory leak.

c) If you are using to commons-logging component (which is a lot of OpenSource components are dependent on commons-logging), it is almost certain to occur Classloader class loader memory leak. Because as WebSphere, Tomcat and other servers use the same core engine to the commons-logging component, and before the application starts commons-logging has been a lot of class ClassLoader loaded system level. By default, a type of load JVM class loader from the start, so that commons-logging system, the priority application EAR is generally higher than those contained in commons-logging, class loader so Classloader memory leak there may appear. Simple analysis of the problem as follows:

1) We generally use the commons-logging application's API to get the Log: protected final Log logger = LogFactory.getLog (getClass ()).

2) To this end we analyze the commons-logging library in LogFactory class, note in which factories are class static variable, but getFactory () method is a static method, belong to the class attribute.
By the following code we can clear that: if LogFactory application EAR on a loading path in the class is loaded, then loaded in the application class loader to create the LogFactory instance (no matter org.apache.commons. logging.impl.LogFactoryImpl or org.apache.commons.logging.impl.Log4jFactory), will be on a class loader in the LogFactory classes mandatory reference and stored in a static class properties variable factories.
Guer even if the application of force to stop the EAR, but because the system class loader loaded LogFactory mandatory reference in the factories created LogFactory this application instance object can not be garbage collection, from the lead all the Class can not be destroyed, the final formation of Classloader class loading memory leak.

LogFactory.java

view plainprint?
public abstract class LogFactory (
protected static Hashtable factories = null;
... ...
public static Log getLog (Class clazz) throws LogConfigurationException (
return getFactory (). getInstance (clazz);
)
public abstract Log getInstance (Class class1) throws LogConfigurationException;
... ...
public static LogFactory getFactory () throws LogConfigurationException (
ClassLoader contextClassLoader = getContextClassLoader ();
LogFactory factory = getCachedFactory (contextClassLoader);
if (factory! = null)
return factory;
... ...
/ / The following code is deleted a lot, mainly used for: to create a new LogFactory loaded by the application object factory
... ...
if (factory! = null) (
cacheFactory (contextClassLoader, factory);
... ...
)
return factory;
)
private static void cacheFactory (ClassLoader classLoader, LogFactory factory) (
if (factory! = null)
if (classLoader == null)
nullClassLoaderFactory = factory;
else
factories.put (classLoader, factory);
)
... ...
)
public abstract class LogFactory (
protected static Hashtable factories = null;
... ...
public static Log getLog (Class clazz) throws LogConfigurationException (
return getFactory (). getInstance (clazz);
)
public abstract Log getInstance (Class class1) throws LogConfigurationException;
... ...
public static LogFactory getFactory () throws LogConfigurationException (
ClassLoader contextClassLoader = getContextClassLoader ();
LogFactory factory = getCachedFactory (contextClassLoader);
if (factory! = null)
return factory;
... ...
/ / The following code is deleted a lot, mainly used for: to create a new LogFactory loaded by the application object factory
... ...
if (factory! = null) (
cacheFactory (contextClassLoader, factory);
... ...
)
return factory;
)
private static void cacheFactory (ClassLoader classLoader, LogFactory factory) (
if (factory! = null)
if (classLoader == null)
nullClassLoaderFactory = factory;
else
factories.put (classLoader, factory);
)
... ...
)

d) place the log4j library to the system class path (eg: JVM, WebSphere Extensions Class loader, WebSphere lib / app Class loader, WebSphere "server" Class loader class path), and use log4j's "Context Repository Selector" mode application access to all logging configuration.
If the time application EAR / WAR contains log4j library will be a Class Cast Exceptions Exception not functioning; if the application EAR / WAR does not contain log4j library, although the applications run normally, but will lead to class loading Classloader memory leak. On log4j's "Context Repository Selector" mode, please refer to http://www.qos.ch/logging/sc.jsp

e) If you develop a component to be used java.beans.Introspector Class / Method MetaData cache may trigger class loading Classloader memory leak.
Analysis of Java Bean for each property, method is more consumption of CPU resources, so in many of the framework-level components such as the Spring in the widespread use of cache JavaBean java.beans.Introspector to Cache definition, Introspector class will use the private static Map beanInfoCache = Collections.synchronizedMap (new WeakHashMap ()) class static variable approaches to the definition of preservation JavaBean.
The Introspector is loaded by the system JVM ClassLoader, so applications will be defined JavaBean Class System class loader loads the Introspector mandatory reference, leading to a state in the application is stopped, all associated with this application class can not be recovered.
Introspector specific code as follows:

java.beans.Introspector.java

view plainprint?
package java.beans;
... ...
public class Introspector (
... ...
private static Map declaredMethodCache = Collections.synchronizedMap (new WeakHashMap ());
private static Map beanInfoCache = Collections.synchronizedMap (new WeakHashMap ());
... ...
public static BeanInfo getBeanInfo (Class <?> beanClass) throws IntrospectionException
(
if (! ReflectUtil.isPackageAccessible (beanClass)) (
return (new Introspector (beanClass, null, USE_ALL_BEANINFO)). getBeanInfo ();
)
BeanInfo bi = (BeanInfo) beanInfoCache.get (beanClass);
if (bi == null) (
bi = (new Introspector (beanClass, null, USE_ALL_BEANINFO)). getBeanInfo ();
beanInfoCache.put (beanClass, bi);
)
return bi;
)
... ...
)
package java.beans;
... ...
public class Introspector (
... ...
private static Map declaredMethodCache = Collections.synchronizedMap (new WeakHashMap ());
private static Map beanInfoCache = Collections.synchronizedMap (new WeakHashMap ());
... ...
public static BeanInfo getBeanInfo (Class <?> beanClass) throws IntrospectionException
(
if (! ReflectUtil.isPackageAccessible (beanClass)) (
return (new Introspector (beanClass, null, USE_ALL_BEANINFO)). getBeanInfo ();
)
BeanInfo bi = (BeanInfo) beanInfoCache.get (beanClass);
if (bi == null) (
bi = (new Introspector (beanClass, null, USE_ALL_BEANINFO)). getBeanInfo ();
beanInfoCache.put (beanClass, bi);
)
return bi;
)
... ...
)

We can also note in the Spring org.springframework.beans.CachedIntrospectionResults class in Spring clear that there may be a memory leak Introspection Classloader class load: "Internal Class that caches JavaBeans (@ link java.beans.PropertyDescriptor) information for a Java class. Not intended for direct use by application code. Necessary for own caching of descriptors within the application's ClassLoader, rather than rely on the JDK's system-wide BeanInfo cache (in order to avoid leaks on ClassLoader shutdown). "
In CachedIntrospectionResults in the same class used to cache static variable classCache class definition, if a stock is to apply the class Spring class loader of the JVM on a system or application server class path, then the class loader may lead to Classloader memory leak .
CachedIntrospectionResults specific code as follows:

org.springframework.beans.CachedIntrospectionResults.java (Note: for Spring2.0.7 later version)

view plainprint?
package org.springframework.beans;
......
final class CachedIntrospectionResults
(
private static final Log logger;
private static final Map classCache = Collections.synchronizedMap (new WeakHashMap ());
private final BeanInfo beanInfo;
private final Map propertyDescriptorCache;
static
(Logger = LogFactory.getLog (org.springframework.beans.CachedIntrospectionResults.class);)
public static CachedIntrospectionResults forClass (Class beanClass)
throws BeansException
(
CachedIntrospectionResults results = null;
Object value = classCache.get (beanClass);
... ...
if (results == null)
(
results = new CachedIntrospectionResults (beanClass);
boolean cacheSafe = isCacheSafe (beanClass);
if (logger.isDebugEnabled ())
logger.debug ("Class [" + beanClass.getName () + "] is" + (cacheSafe? "": "not") + "cache-safe");
if (cacheSafe)
classCache.put (beanClass, results);
else
classCache.put (beanClass, new WeakReference (results));
) Else
if (logger.isDebugEnabled ())
logger.debug ("Using cached introspection results for class [" + beanClass.getName () + "]");
return results;
)
private CachedIntrospectionResults (Class clazz) throws BeansException
(
... ...
beanInfo = Introspector.getBeanInfo (clazz);
Class classToFlush = clazz;
... ...
)
... ...
)
package org.springframework.beans;
......
final class CachedIntrospectionResults
(
private static final Log logger;
private static final Map classCache = Collections.synchronizedMap (new WeakHashMap ());
private final BeanInfo beanInfo;
private final Map propertyDescriptorCache;
static
(Logger = LogFactory.getLog (org.springframework.beans.CachedIntrospectionResults.class);)
public static CachedIntrospectionResults forClass (Class beanClass)
throws BeansException
(
CachedIntrospectionResults results = null;
Object value = classCache.get (beanClass);
... ...
if (results == null)
(
results = new CachedIntrospectionResults (beanClass);
boolean cacheSafe = isCacheSafe (beanClass);
if (logger.isDebugEnabled ())
logger.debug ("Class [" + beanClass.getName () + "] is" + (cacheSafe? "": "not") + "cache-safe");
if (cacheSafe)
classCache.put (beanClass, results);
else
classCache.put (beanClass, new WeakReference (results));
) Else
if (logger.isDebugEnabled ())
logger.debug ("Using cached introspection results for class [" + beanClass.getName () + "]");
return results;
)
private CachedIntrospectionResults (Class clazz) throws BeansException
(
... ...
beanInfo = Introspector.getBeanInfo (clazz);
Class classToFlush = clazz;
... ...
)
... ...
)

f) in the commons-beanutils 1.7 version (including 1.7 version) of the component class loader exists Classloader memory leak, only the latest 1.8.0Beta corrected this potential problem,
Problem description:
* [BEANUTILS-59] - Memory leak on webapp undeploy in WrapDynaClass
* [BEANUTILS-156] - Memory leak on webapp undeploy in MappedPropertyDescriptor
Detailed description please refer to: http://commons.apache.org/beanutils/v1.8.0-BETA/RELEASE-NOTES.txt

g) used in the application of MethodUtils commons-beanutils to the methods of the class Method to operate, it also exists Classloader class loader memory leak possible.
If commons-beanutils library placed on the application-level class loading path, and there are other applications (or system code) prior to use in this application the same way MethodUtils to operate on the Class's Method (in the other class loader loading MethodUitls), then the Classloader class loading inevitable memory leak. We can refer to MethodUtils the corresponding code can be very intuitive positioning:

view plainprint?
package org.apache.commons.beanutils;
... ...
public class MethodUtils
(
private static WeakHashMap cache = new WeakHashMap ();
... ...
public static Method getAccessibleMethod (Class clazz, String methodName, Class parameterTypes [])
(
MethodDescriptor md;
Method method;
md = new MethodDescriptor (clazz, methodName, parameterTypes, true);
method = (Method) cache.get (md);
if (method! = null)
return method;
try (
method = getAccessibleMethod (clazz.getMethod (methodName, parameterTypes));
cache.put (md, method);
return method;
) Catch (NoSuchMethodException e) (
return null;
)
... ...
)
package org.apache.commons.beanutils;
... ...
public class MethodUtils
(
private static WeakHashMap cache = new WeakHashMap ();
... ...
public static Method getAccessibleMethod (Class clazz, String methodName, Class parameterTypes [])
(
MethodDescriptor md;
Method method;
md = new MethodDescriptor (clazz, methodName, parameterTypes, true);
method = (Method) cache.get (md);
if (method! = null)
return method;
try (
method = getAccessibleMethod (clazz.getMethod (methodName, parameterTypes));
cache.put (md, method);
return method;
) Catch (NoSuchMethodException e) (
return null;
)
... ...
)

h) If the application using the Java 1.5 syntax defined enum class, and this defines the class placed in the application-level class loading path. First, we develop the application in the class loader to load and initialize the application-defined enum class, then other applications EAR / WAR (or system code) also uses this definition of the enum type, in and to such enum attribute references placed (for other applications) class Servlet static variable or class variable, then we develop the application Classloader class loader will not be recycled and eventually inevitable memory leak. For example:

OperationEnum.java

view plainprint?
package com.test.enumeration;
public enum OperationEnum (
QUOTE (1), ISSUE (2), RENEW (4), CANCEL (12),
ENDORSE (16), CHANGE (64), REINSTATE (192);
private int operation = 0;
private OperationEnum (int op) (
this.operation = op;
)
public boolean isNewOperation () (
return (this.operation == 2) | |
(This.operation == 4) | |
(This.operation == 192);
)
)
package com.test.enumeration;
public enum OperationEnum (
QUOTE (1), ISSUE (2), RENEW (4), CANCEL (12),
ENDORSE (16), CHANGE (64), REINSTATE (192);
private int operation = 0;
private OperationEnum (int op) (
this.operation = op;
)
public boolean isNewOperation () (
return (this.operation == 2) | |
(This.operation == 4) | |
(This.operation == 192);
)
)

Other applications use the EAR to the above sample code defines enum class

view plainprint?
public class LeakCauseServletInOtherApp extends HttpServlet (
private final OperationEnum operation = OperationEnum.CHANGE; / /
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
doSomething (request, response);
)
... ...
)
public class LeakCauseServletInOtherApp extends HttpServlet (
private final OperationEnum operation = OperationEnum.CHANGE; / /
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException (
doSomething (request, response);
)
... ...
)

i) result in class loading Classloader memory leak is another important factor: if the framework or application to use ThreadLocal thread-data space to store the instance of the object, you must know in WAS and other application server instances are of the thread pool state, WebContainer by the application server containers such as to maintain the thread instance.
Even if the application is stopped, and the state of the thread pool instance will still be viable operations, if the application Web Servlet thread running process instances are stored in the ThreadLocal object is not properly removed, can cause the thread class loader memory leak problem.
In the old version of DOM4J, Mozilla Rhino, CGLIB there this type of thread memory leak, please use the latest version of these components to avoid the occurrence of such leakage.

1) Hibernate 3.2.2 version of the thread ThreadLocal variable exists in the memory leak problem in version 3.2.3 be modified. For details, please refer to "Big Memory leak in the use of CGLIB" http://opensource.atlassian.com/projects/hibernate/browse/HHH-2481

2) CGLIB 2.1 memory leak exists ThreadLocal thread-variable problem, in the latest version 2.1_3 of the problem should be modified. For more information see
http://sourceforge.net/tracker/index.php?func=detail&aid=1257327&group_id=56933&atid=482368
http://sourceforge.net/tracker/index.php?func=detail&aid=1291183&group_id=56933&atid=482370
http://jira.jboss.com/jira/browse/JBAS-2256

3) dom4j 1.6 version before the existence of variable memory leaks ThreadLocal thread in the 1.6 version later this issue is resolved.
Problem Description: https: / / sourceforge.net / tracker / index.php? Func = detail & aid = 1070309 & group_id = 16035 & atid = 116035
Bug revised description: "Added a SingletonStrategyclass for managing singletons. This allows to use different strategies for singletons, like: one instance per VM, one instance per thread, ... This change removed the usage of ThreadLocals."
http://www.dom4j.org/changes-report.html

ClassLoader class loader memory leak problem solution
ClassLoader class loader memory leak problem solving principles:

1, do not apply to use of the library onto the JRE or WebSphere server class loader path, try to use the library to keep the EAR or WAR / WEB-INF / Lib path.

2, as set in the WebSphere server class loading order "Child-First ClassLoaders" / "Parent-Last ClassLoaders".

3, for DOM4J, Mozilla Rhino, CGLIB Make sure to use the latest version, and confirm the library stored in the application under the EAR level.

4, try to avoid using Java 1.5 syntax of enum class, if you use the enum class, to be sure to keep the development of libraries in the application EAR class loader under this level, but must not be placed or JVM library path to the WebSphere in.

5, using the latest version of commons-logging, and confirm the library stored in the application under the EAR level.

6, using the latest version of commons-beanutils, and confirm the library stored in the application under the EAR level, do not be put into WebSphere or JVM library path.

7, using the latest version of log4j, and confirm the library stored in the application under the EAR level, do not be put into WebSphere or JVM library path.

8, do not use in a production environment DriverManager.

9, do not use in a production environment as commons-dbcp data source implementation, recommended application server data source.

10, do not use in applications java.util.logging.Level.

Unable to avoid the commons-logging inventory is WebSphere Application Server class path and a large number of J2EE OpenSource class component uses java.beans.Introspector to the fact that the definition of Cache cache JavaBean for this situation and how we respond to and deal with it?

As we repeat the above Class loading problem to reproduce prepared ClassLoaderTestServlet sample, using the most simple way to call a Spring managed object class instance StaticClass sc, took place on the notorious Class class loader memory leak problem. How to avoid this problem happening?

Memory leak problem for java.beans.Introspector

In fact, later in the Spring framework version 2.0.7 has been corresponding with this solution provides a dedicated memory leak problem Java.beans.Introspector helper classes: org.springframework.web.util.IntrospectorCleanupListener, together with there are special instructions document description. If the original document as follows:

"

Listener that flushes the JDK's JavaBeans Introspector cache on web app shutdown. Register this listener in your web.xml to guarantee proper release of the web application class loader and its loaded classes.

If the JavaBeans Introspector has been used to analyze application classes, the system-level Introspector cache will hold a hard reference to those classes. Consequently, those classes and the web application class loader will not be garbage-collected on web app shutdown! This listener performs proper cleanup, to allow for garbage collection to take effect.

Unfortunately, the only way to clean up the Introspector is to flush the entire cache, as there is no way to specifically determine the application's classes referenced there. This will remove cached introspection results for all other applications in the server too.

Note that this listener is not necessary when using Spring's beans infrastructure within the application, as Spring's own introspection results cache will immediately flush an analyzed class from the JavaBeans Introspector cache and only hold a cache within the application's own ClassLoader. Although Spring itself does not create JDK Introspector leaks, note that this listener should nevertheless be used in scenarios where the Spring framework classes themselves reside in a 'common' ClassLoader (such as the system ClassLoader). In such a scenario, this listener will properly clean up Spring's introspection cache.

Application classes hardly ever need to use the JavaBeans Introspector directly, so are normally not the cause of Introspector resource leaks. Rather, many libraries and frameworks do not clean up the Introspector: eg Struts and Quartz.

Note that a single such Introspector leak will cause the entire web app class loader to not get garbage collected! This has the consequence that you will see all the application's static class resources (like singletons) around after web app shutdown, which is not the fault of those classes!

This listener should be registered as the first one in web.xml, before any application listeners such as Spring's ContextLoaderListener. This allows the listener to take full effect at the right time of the lifecycle.

"

In the above documents, we can clear that, if put to the Spring library system or application server, a JVM-level library path, we must configure org.springframework.web.util.IntrospectorCleanupListener in web.xml in order to prevent possible Introspector Spring in a memory leak.

web.xml sample configuration is as follows:

web.xml configuration file (this Spring Listener Spring2.0 after only version that exists)

view plainprint?
<? Xml version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.4"
xmlns = " http://java.sun.com/xml/ns/j2ee "
xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance "
xsi: schemaLocation = " http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<display-name> ClassLoader </ display-name>
<context-param>
<param-name> contextConfigLocation </ param-name>
<param-value> classpath *: spring / *. xml </ param-value>
</ Context-param>
<! - Spring Refresh Introspector prevent memory leaks, recommend to the Listener in the first place, at least in the first Spring Related Listener ->
<listener>
<listener-class> org.springframework.web.util.IntrospectorCleanupListener </ listener-class>
</ Listener>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ Listener>
... ...
<? Xml version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.4"
xmlns = " http://java.sun.com/xml/ns/j2ee "
xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance "
xsi: schemaLocation = " http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<display-name> ClassLoader </ display-name>
<context-param>
<param-name> contextConfigLocation </ param-name>
<param-value> classpath *: spring / *. xml </ param-value>
</ Context-param>
<! - Spring Refresh Introspector prevent memory leaks, recommend to the Listener in the first place, at least in the first Spring Related Listener ->
<listener>
<listener-class> org.springframework.web.util.IntrospectorCleanupListener </ listener-class>
</ Listener>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ Listene
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Class class loader on the issue of memory leaks

  • Rails2.0.2 change the default DB adpter

    In Rails2.0.2 rails demo ... ... MissingSourceFile in SayController # hello no such file to load - sqlite3 RAILS_ROOT: / home / kenb / rails-projects / demo ... ... Checked config / database.yml, adpter default is set become the sqlite3. Check the ra ...

  • ROR resources

    Ruby Web site resources: ruby official website: http://www.ruby-lang.org ruby doc official website: http://www.ruby-doc.org rubyonrails official website: http://www.rubyonrails.org programming ruby online edition (Ruby studying the "Bible") ...

  • Struts2 Spring Hibernate integration of easy

    1. Add Spring 2.0 in Libraries Choose the following four jar, and configure the / WEB-INF/lib under Spring2.0 AOP Libraries Spring2.0 Core Libraries Spring2.0 Persistence Core Libraries Spring2.0 WEb Libraries At the same time, the applicationContext ...

  • Struts2 Spring Hibernate's easy to integrate

    1. Add Spring 2.0 in Libraries Choose the following four jar, and configure the / WEB-INF/lib under Spring2.0 AOP Libraries Spring2.0 Core Libraries Spring2.0 Persistence Core Libraries Spring2.0 WEb Libraries At the same time, the applicationContext ...

  • NoClassDefFoundError: javax / servlet / Servlet

    In the project in order to achieve a listener in web.xml set up a listener, did start in Tomcat actually occurred after java.lang.NoClassDefFoundError: javax / servlet / ServletContextListener this anomaly google and found the reasons for the lack of serv

  • hibernate using c3p0 connection pooling

    Private http://www.lifevv.com/tenyo/doc/20070605102040991.html c3p0 for open source's JDBC connection pool, with the release hibernate. This article describes how to use the hibernate configuration in c3p0. c3p0 connection pool configuration is v ...

  • Hibernate configuration parameters hibernate.hbm2ddl.auto

    Hibernate in the configuration file: <properties> <property name="hibernate.hbm2ddl.auto" value="create" /> </ properties> Parameter Description: validate load hibernate, the authentication to create a database t ...

  • Build flex + spring + blazeds + hibernate application

    Build flex + spring + blazeds + hibernate application First, set up the project blazeds 1, will blazeds.war extract to a directory, such as: myflex /; 2, set up java works were such as: MyFlex, in the orientation of selection create project from exis ...

  • In the servlet use Bean

    According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries