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:
parent
a89e88fa18
commit
2ce3aa1f09
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -279,8 +279,10 @@ public abstract class AbstractServiceRegistryImpl
|
|||
}
|
||||
serviceBindingMap.clear();
|
||||
|
||||
if (parent!=null){
|
||||
parent.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends Service> void stopService(ServiceBinding<R> binding) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue