@Test public void resolve() throws ClassNotFoundException { ClassResolver delegate = new ClassLoaderClassResolver(CachingClassResolverTest.class.getClassLoader()); ClassResolver resolver = new CachingClassResolver(delegate, new ConcurrentHashMap<String, Class<?>>()); long start = System.nanoTime(); resolver.resolve("com.fr.swift.jdbc.rpc.serializable.clazz.CachingClassResolverTest"); long first = System.nanoTime() - start; System.out.println(first); start = System.nanoTime(); resolver.resolve("com.fr.swift.jdbc.rpc.serializable.clazz.CachingClassResolverTest"); long cached = System.nanoTime() - start; System.out.println(cached); assertTrue(cached <= first); }
@Override public Class<?> resolve(String className) throws ClassNotFoundException { Class<?> clazz; clazz = classCache.get(className); if (clazz != null) { return clazz; } clazz = delegate.resolve(className); classCache.put(className, clazz); return clazz; }
CachingClassResolver implements ClassResolver { @Override public Class<?> resolve(String className) throws ClassNotFoundException { Class<?> clazz; clazz = classCache.get(className); if (clazz != null) { return clazz; } clazz = delegate.resolve(className); classCache.put(className, clazz); return clazz; } }
CachingClassResolver implements ClassResolver { @Override public Class<?> resolve(String className) throws ClassNotFoundException { Class<?> clazz; clazz = classCache.get(className); if (clazz != null) { return clazz; } clazz = delegate.resolve(className); classCache.put(className, clazz); return clazz; } CachingClassResolver(ClassResolver delegate, Map<String, Class<?>> classCache); }
CachingClassResolver implements ClassResolver { @Override public Class<?> resolve(String className) throws ClassNotFoundException { Class<?> clazz; clazz = classCache.get(className); if (clazz != null) { return clazz; } clazz = delegate.resolve(className); classCache.put(className, clazz); return clazz; } CachingClassResolver(ClassResolver delegate, Map<String, Class<?>> classCache); @Override Class<?> resolve(String className); }
CachingClassResolver implements ClassResolver { @Override public Class<?> resolve(String className) throws ClassNotFoundException { Class<?> clazz; clazz = classCache.get(className); if (clazz != null) { return clazz; } clazz = delegate.resolve(className); classCache.put(className, clazz); return clazz; } CachingClassResolver(ClassResolver delegate, Map<String, Class<?>> classCache); @Override Class<?> resolve(String className);  }