You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2009/08/14 15:43:25 UTC

svn commit: r804225 - /incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java

Author: schor
Date: Fri Aug 14 13:43:25 2009
New Revision: 804225

URL: http://svn.apache.org/viewvc?rev=804225&view=rev
Log:
[UIMA-1493] [UIMA-1494] fix synchronization and don't forward finalize call

Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java?rev=804225&r1=804224&r2=804225&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/analysis_engine/impl/PearAnalysisEngineWrapper.java Fri Aug 14 13:43:25 2009
@@ -86,8 +86,9 @@
    // consisting of the "class path" and "data path", the 
    // Resource Manager for that combination.
 
-   static private Map<ResourceManager, Map<StringPair, ResourceManager>> cachedResourceManagers = Collections
-         .synchronizedMap(new WeakHashMap<ResourceManager, Map<StringPair, ResourceManager>>(4));
+   // note: all accesses to this are synchronized
+   static private Map<ResourceManager, Map<StringPair, ResourceManager>> cachedResourceManagers =
+     new WeakHashMap<ResourceManager, Map<StringPair, ResourceManager>>(4);
 
    private AnalysisEngine ae = null;
 
@@ -101,7 +102,7 @@
       return result;
    }
 
-   private ResourceManager createRM(StringPair sp, PackageBrowser pkgBrowser, ResourceManager parentResourceManager)
+   private synchronized ResourceManager createRM(StringPair sp, PackageBrowser pkgBrowser, ResourceManager parentResourceManager)
          throws MalformedURLException {
       // create UIMA resource manager and apply pear settings
 //      ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager();
@@ -227,18 +228,20 @@
       StringPair sp = new StringPair(classPath, dataPath);
       ResourceManager innerRM;
 
-      Map<StringPair, ResourceManager> c1 = cachedResourceManagers.get(applicationRM);
-      if (null == c1) {
-        innerRM = createRM(sp, pkgBrowser, applicationRM);
-        cachedResourceManagers.put(applicationRM, createRMmap(sp, innerRM));
-      } else {
-        innerRM = c1.get(sp);
-        if (null == innerRM) {
+      synchronized (cachedResourceManagers) {
+        Map<StringPair, ResourceManager> c1 = cachedResourceManagers.get(applicationRM);
+        if (null == c1) {
           innerRM = createRM(sp, pkgBrowser, applicationRM);
-          c1.put(sp, innerRM);
-          UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG, this.getClass().getName(),
-              "initialize", LOG_RESOURCE_BUNDLE, "UIMA_pear_runtime_add_RM_map",
-              new Object[] { sp.classPath, sp.dataPath });
+          cachedResourceManagers.put(applicationRM, createRMmap(sp, innerRM));
+        } else {
+          innerRM = c1.get(sp);
+          if (null == innerRM) {
+            innerRM = createRM(sp, pkgBrowser, applicationRM);
+            c1.put(sp, innerRM);
+            UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG, this.getClass().getName(),
+                "initialize", LOG_RESOURCE_BUNDLE, "UIMA_pear_runtime_add_RM_map",
+                new Object[] { sp.classPath, sp.dataPath });
+          }
         }
       }
 
@@ -429,15 +432,9 @@
     ((AnalysisEngineImplBase) ae).exitProcess();
   }
 
-  /* (non-Javadoc)
-   * @see org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase#finalize()
-   */
-  @Override
-  protected void finalize() throws Throwable {
-    ((AnalysisEngineImplBase) ae).finalize();
-  }
-
-
+  // finalize method not forwarded
+  // finalize will be called on the object by the GC
+  
   /* (non-Javadoc)
    * @see org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase#getMBeanNamePrefix()
    */