Author: ssmaeklu
Date: 2007-06-21 13:26:36 +0200 (Thu, 21 Jun 2007)
New Revision: 5375

Modified:
   
trunk/site-spi/src/main/java/no/schibstedsok/searchportal/site/config/ResourceClassLoader.java
Log:
Do not try to load non existent classes over and over again

Modified: 
trunk/site-spi/src/main/java/no/schibstedsok/searchportal/site/config/ResourceClassLoader.java
===================================================================
--- 
trunk/site-spi/src/main/java/no/schibstedsok/searchportal/site/config/ResourceClassLoader.java
      2007-06-21 10:14:34 UTC (rev 5374)
+++ 
trunk/site-spi/src/main/java/no/schibstedsok/searchportal/site/config/ResourceClassLoader.java
      2007-06-21 11:26:36 UTC (rev 5375)
@@ -4,18 +4,23 @@
 import no.schibstedsok.searchportal.site.SiteContext;
 import org.apache.log4j.Logger;
 
+import java.util.*;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
 /**
  * @author magnuse
  */
 public abstract class ResourceClassLoader extends ClassLoader {
 
-    private static final Logger LOG = 
Logger.getLogger(ResourceClassLoader.class);
-
     /**  Context needed by this class. */
     public interface Context extends BytecodeContext, SiteContext {}
 
     private final Context context;
 
+    private Collection<String> notFound = 
Collections.synchronizedCollection(new HashSet<String>());
+    private ReadWriteLock notFoundLock = new ReentrantReadWriteLock();
+
     /**
      * Creates a new resource class loader for a site.
      *
@@ -47,6 +52,16 @@
      */
     protected Class<?> findClass(final String className) throws 
ClassNotFoundException {
 
+        try {
+            // Optimization. Do not try to load class if it has not been found 
before.
+            notFoundLock.readLock().lock();
+            if (notFound.contains(className)) {
+                throw new ClassNotFoundException(className + " not found");
+            }
+        } finally {
+            notFoundLock.readLock().unlock();
+        }
+
         final BytecodeLoader loader = context.newBytecodeLoader(context, 
className, getJarName());
         loader.abut();
 
@@ -54,6 +69,12 @@
 
         // Resource loader loaded empty result means class was not found.
         if (bytecode.length == 0) {
+            try {
+                notFoundLock.writeLock().lock();
+                notFound.add(className);
+            } finally {
+                notFoundLock.writeLock().unlock();
+            }
             throw new ClassNotFoundException(className + " not found");
         }
 

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to