Fixes issue 25015: Many instances of WidgetClass consuming tomcat memory
authorMartin Taal <martin.taal@openbravo.com>
Tue, 05 Nov 2013 10:50:44 +0100
changeset 21427 d152fbd22bdd
parent 21426 2de3e09aac30
child 21428 62cfb2e198ef
Fixes issue 25015: Many instances of WidgetClass consuming tomcat memory
The ComponentProviders are applicationscoped, this ment that the member instances and its references were maintained throughout the lifetime of the application. Causing each time a new component being created and stored there. The change creates a new instance dynamically all the time.
.project
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponentProvider.java
--- a/.project	Tue Nov 05 14:06:17 2013 +0100
+++ b/.project	Tue Nov 05 10:50:44 2013 +0100
@@ -23,4 +23,11 @@
 		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
 		<nature>org.openarchitectureware.base.oawNature</nature>
 	</natures>
+	<linkedResources>
+		<link>
+			<name>modules/org.openbravo.client.analytics/mondrian-3.5.0-src</name>
+			<type>2</type>
+			<location>/home/mtaal/mydownloads/reporting/mondrian/mondrian-3.5.0/mondrian-3.5.0-src</location>
+		</link>
+	</linkedResources>
 </projectDescription>
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponentProvider.java	Tue Nov 05 14:06:17 2013 +0100
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/BaseComponentProvider.java	Tue Nov 05 10:50:44 2013 +0100
@@ -25,10 +25,7 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.enterprise.inject.Any;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-
+import org.openbravo.base.weld.WeldUtils;
 import org.openbravo.client.kernel.BaseComponentProvider.ComponentResource.ComponentResourceType;
 import org.openbravo.model.ad.module.Module;
 
@@ -43,10 +40,6 @@
 
   private static Map<String, List<String>> appDependencies = new HashMap<String, List<String>>();
 
-  @Inject
-  @Any
-  private Instance<Component> components;
-
   /**
    * Return a component of the correct implementation using Weld.
    * 
@@ -55,7 +48,7 @@
    * @return an instance of clz
    */
   protected <U extends Component> U getComponent(Class<U> clz) {
-    return (U) components.select(clz).get();
+    return (U) WeldUtils.getInstanceFromStaticBeanManager(clz);
   }
 
   public Module getModule() {