Merge pull request #37 from marschall/small-memory-fixes

* small-memory-fixes:
  Optimize memory usage in factory *Metadata classes
This commit is contained in:
Chris Beams 2012-05-16 13:06:03 +03:00
commit 39f74b2374
2 changed files with 32 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -247,15 +247,21 @@ public class InitDestroyAnnotationBeanPostProcessor
public LifecycleMetadata(Class<?> targetClass, Collection<LifecycleElement> initMethods,
Collection<LifecycleElement> destroyMethods) {
this.initMethods = Collections.synchronizedSet(new LinkedHashSet<LifecycleElement>());
if (!initMethods.isEmpty()) {
this.initMethods = Collections.synchronizedSet(new LinkedHashSet<LifecycleElement>(initMethods.size()));
for (LifecycleElement element : initMethods) {
if (logger.isDebugEnabled()) {
logger.debug("Found init method on class [" + targetClass.getName() + "]: " + element);
}
this.initMethods.add(element);
}
}
else {
this.initMethods = Collections.emptySet();
}
this.destroyMethods = Collections.synchronizedSet(new LinkedHashSet<LifecycleElement>());
if (!destroyMethods.isEmpty()) {
this.destroyMethods = Collections.synchronizedSet(new LinkedHashSet<LifecycleElement>(destroyMethods.size()));
for (LifecycleElement element : destroyMethods) {
if (logger.isDebugEnabled()) {
logger.debug("Found destroy method on class [" + targetClass.getName() + "]: " + element);
@ -263,6 +269,10 @@ public class InitDestroyAnnotationBeanPostProcessor
this.destroyMethods.add(element);
}
}
else {
this.destroyMethods = Collections.emptySet();
}
}
public void checkConfigMembers(RootBeanDefinition beanDefinition) {
synchronized(this.initMethods) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -54,7 +54,8 @@ public class InjectionMetadata {
public InjectionMetadata(Class targetClass, Collection<InjectedElement> elements) {
this.injectedElements = Collections.synchronizedSet(new LinkedHashSet<InjectedElement>());
if (!elements.isEmpty()) {
this.injectedElements = Collections.synchronizedSet(new LinkedHashSet<InjectedElement>(elements.size()));
for (InjectedElement element : elements) {
if (logger.isDebugEnabled()) {
logger.debug("Found injected element on class [" + targetClass.getName() + "]: " + element);
@ -62,6 +63,10 @@ public class InjectionMetadata {
this.injectedElements.add(element);
}
}
else {
this.injectedElements = Collections.emptySet();
}
}
public void checkConfigMembers(RootBeanDefinition beanDefinition) {
synchronized(this.injectedElements) {