1 26 27 28 package org.objectweb.mobilitools.smi.lib; 29 30 31 import java.util.Hashtable ; 32 33 34 42 public class ClassCache extends Hashtable 43 { 44 static protected Hashtable caches = new Hashtable (); 45 protected volatile long refCount=0; 46 47 48 55 static public synchronized ClassCache getCache(String codebase) 56 { 57 ClassCache cache = (ClassCache)caches.get(codebase); 58 if (cache == null) 59 { 60 cache = new ClassCache(); 61 caches.put(codebase, cache); 62 } 63 return cache; 64 } 65 66 67 72 static public synchronized void inc(String codebase) 73 { 74 ClassCache cache = getCache(codebase); 75 synchronized (cache) 76 { 77 if (cache != null) 78 { 79 ++cache.refCount; 80 } 81 } 82 } 83 84 85 91 static public synchronized void dec(String codebase) 92 { 93 ClassCache cache = getCache(codebase); 94 synchronized (cache) 95 { 96 --cache.refCount; 97 if (cache.refCount == 0) 98 { 99 cache.clear(); 100 caches.remove(codebase); 101 } 102 else if (cache.refCount < 0) 103 { 104 throw new Error ("cache.refCount negatif pour codebase " + codebase); 105 } 106 } 107 } 108 109 110 protected ClassCache() 111 { 112 super(); 113 } 114 } 115 | Popular Tags |