HHH-8363 Some more mem leak fixes

Conflicts:
	hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java
	hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java
	hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java
This commit is contained in:
Tomaz Cerar 2013-09-17 18:46:59 -04:00 committed by Brett Meyer
parent a89e88fa18
commit 2ce3aa1f09
4 changed files with 28 additions and 7 deletions

View File

@ -52,7 +52,7 @@ import org.jboss.logging.Logger;
public class ClassLoaderServiceImpl implements ClassLoaderService {
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
private final ClassLoader aggregatedClassLoader;
private AggregatedClassLoader aggregatedClassLoader;
private final Map<Class, ServiceLoader> serviceLoaders = new HashMap<Class, ServiceLoader>();
@ -256,10 +256,14 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
serviceLoader.reload(); // clear service loader providers
}
serviceLoaders.clear();
if (aggregatedClassLoader!=null){
aggregatedClassLoader.destroy();
aggregatedClassLoader = null;
}
}
private static class AggregatedClassLoader extends ClassLoader {
private final ClassLoader[] individualClassLoaders;
private ClassLoader[] individualClassLoaders;
private AggregatedClassLoader(final LinkedHashSet<ClassLoader> orderedClassLoaderSet) {
super( null );
@ -314,6 +318,10 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
throw new ClassNotFoundException( "Could not load requested class : " + name );
}
public void destroy() {
individualClassLoaders = null;
}
}
}

View File

@ -278,8 +278,10 @@ public abstract class AbstractServiceRegistryImpl
serviceBindingList.clear();
}
serviceBindingMap.clear();
parent.destroy();
if (parent!=null){
parent.destroy();
}
}
@Override

View File

@ -23,6 +23,7 @@
*/
package org.hibernate.envers.configuration;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;
@ -57,7 +58,7 @@ public class AuditConfiguration {
private final RevisionInfoQueryCreator revisionInfoQueryCreator;
private final RevisionInfoNumberReader revisionInfoNumberReader;
private final ModifiedEntityNamesReader modifiedEntityNamesReader;
private final ClassLoaderService classLoaderService;
private ClassLoaderService classLoaderService;
public AuditEntitiesConfiguration getAuditEntCfg() {
return auditEntCfg;
@ -182,4 +183,13 @@ public class AuditConfiguration {
return verCfg;
}
public void destroy() {
for (Map.Entry<Configuration, AuditConfiguration> c: new HashSet<Map.Entry<Configuration, AuditConfiguration>>(cfgs.entrySet())){
if (c.getValue() == this){//this is nasty cleanup fix, whole static CFGS should be reworked
cfgs.remove(c.getKey());
}
}
classLoaderService = null;
}
}

View File

@ -46,6 +46,7 @@ public class EnversIntegrator implements Integrator {
private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, EnversIntegrator.class.getName() );
public static final String AUTO_REGISTER = "hibernate.listeners.envers.autoRegister";
private AuditConfiguration enversConfiguration;
@Override
public void integrate(
@ -61,7 +62,7 @@ public class EnversIntegrator implements Integrator {
EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE );
final AuditConfiguration enversConfiguration = AuditConfiguration.getFor( configuration, serviceRegistry.getService( ClassLoaderService.class ) );
enversConfiguration = AuditConfiguration.getFor( configuration, serviceRegistry.getService( ClassLoaderService.class ) );
if (enversConfiguration.getEntCfg().hasAuditedEntities()) {
listenerRegistry.appendListeners( EventType.POST_DELETE, new EnversPostDeleteEventListenerImpl( enversConfiguration ) );
@ -75,7 +76,7 @@ public class EnversIntegrator implements Integrator {
@Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
// nothing to do afaik
enversConfiguration.destroy();
}
/**