List of usage examples for java.lang.ref ReferenceQueue ReferenceQueue
public ReferenceQueue()
From source file:ReferenceValueMap.java
/** * Clone method./*from www.j a v a 2 s . co m*/ * @return Clone of this object. **/ public Object clone() { reap(); ReferenceValueMap rvm = null; try { rvm = (ReferenceValueMap) super.clone(); } catch (CloneNotSupportedException e) { // Do nothing } rvm.map = (HashMap) map.clone(); // to preserve initialCapacity, loadFactor rvm.map.clear(); rvm.reaped = new ReferenceQueue(); rvm.putAll(entrySet()); return rvm; }
From source file:com.silverwrist.dynamo.index.IndexManagerObject.java
public IndexManagerObject() { m_resolvers = new Hashtable(); m_indexcache = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.SOFT); m_cleanupqueue = new ReferenceQueue(); }
From source file:SoftValueMap.java
/** * Constructs a SoftValueMap with specified initial capacity, load factor, * and cleared value removal frequencies. * * @param initialCapacity initial number of hash buckets in the table * [may not be negative, 0 is equivalent to 1]. * @param loadFactor the load factor to use to determine rehashing points * [must be in (0.0, 1.0] range].//from w w w. j av a 2 s .com * @param readClearCheckFrequency specifies that every readClearCheckFrequency * {@link #get} should check for and remove all mappings whose soft values * have been cleared by the garbage collector [may not be less than 1]. * @param writeClearCheckFrequency specifies that every writeClearCheckFrequency * {@link #put} should check for and remove all mappings whose soft values * have been cleared by the garbage collector [may not be less than 1]. */ public SoftValueMap(int initialCapacity, final float loadFactor, final int readClearCheckFrequency, final int writeClearCheckFrequency) { if (initialCapacity < 0) throw new IllegalArgumentException("negative input: initialCapacity [" + initialCapacity + "]"); if ((loadFactor <= 0.0) || (loadFactor >= 1.0 + 1.0E-6)) throw new IllegalArgumentException("loadFactor not in (0.0, 1.0] range: " + loadFactor); if (readClearCheckFrequency < 1) throw new IllegalArgumentException( "readClearCheckFrequency not in [1, +inf) range: " + readClearCheckFrequency); if (writeClearCheckFrequency < 1) throw new IllegalArgumentException( "writeClearCheckFrequency not in [1, +inf) range: " + writeClearCheckFrequency); if (initialCapacity == 0) initialCapacity = 1; m_valueReferenceQueue = new ReferenceQueue(); m_loadFactor = loadFactor; m_sizeThreshold = (int) (initialCapacity * loadFactor); m_readClearCheckFrequency = readClearCheckFrequency; m_writeClearCheckFrequency = writeClearCheckFrequency; m_buckets = new SoftEntry[initialCapacity]; }
From source file:WeakSet.java
/** Constructs a new, empty set; * * @param initialCapacity initial capacity * @param loadFactor load factor/* w w w. j a v a2s .c o m*/ */ public WeakSet(int initialCapacity, float loadFactor) { if ((initialCapacity <= 0) || (loadFactor <= 0)) { throw new IllegalArgumentException(); } size = 0; modcount = 0; this.loadFactor = loadFactor; nullCount = 0; refq = new ReferenceQueue<E>(); entries = Entry.createArray(initialCapacity); iterChain = null; }
From source file:org.enerj.apache.commons.beanutils.BeanificationTestCase.java
/** Tests whether classloaders and beans are released from memory by the map used by beanutils */ public void testMemoryLeak2() throws Exception { // tests when the map used by beanutils has the right behaviour if (isPre14JVM()) { System.out.println("WARNING: CANNOT TEST MEMORY LEAK ON PRE1.4 JVM"); return;//from w w w .j a va 2s . c o m } // many thanks to Juozas Baliuka for suggesting this methodology TestClassLoader loader = new TestClassLoader(); ReferenceQueue queue = new ReferenceQueue(); WeakReference loaderReference = new WeakReference(loader, queue); Integer test = new Integer(1); WeakReference testReference = new WeakReference(test, queue); //Map map = new ReferenceMap(ReferenceMap.WEAK, ReferenceMap.HARD, true); Map map = new WeakHashMap(); map.put(loader, test); assertEquals("In map", test, map.get(loader)); assertNotNull("Weak reference released early (1)", loaderReference.get()); assertNotNull("Weak reference released early (2)", testReference.get()); // dereference strong references loader = null; test = null; int iterations = 0; int bytz = 2; while (true) { System.gc(); if (iterations++ > MAX_GC_ITERATIONS) { fail("Max iterations reached before resource released."); } map.isEmpty(); if (loaderReference.get() == null && testReference.get() == null) { break; } else { // create garbage: byte[] b = new byte[bytz]; bytz = bytz * 2; } } }
From source file:org.paxle.core.doc.impl.CommandTracker.java
@Activate protected void activate(Map<String, Object> props) { this.refQueue = new ReferenceQueue<ICommand>(); this.commandIDTable = new Hashtable<Long, WeakReference<ICommand>>(); this.commandLocationTable = new Hashtable<URI, WeakReference<ICommand>>(); this.destroyedCommandMap = new LinkedList<DestroyedCommandData>(); this.setName("CommandTracker"); this.start(); }
From source file:WeakIdentityMap.java
public WeakIdentityMap(int initialCapacity, float loadFactor) { if (initialCapacity <= 0) { throw new IllegalArgumentException("Initial capacity must be greater than 0"); }/*from www .ja v a 2 s . c o m*/ if (loadFactor <= 0 || Float.isNaN(loadFactor)) { throw new IllegalArgumentException("Load factor must be greater than 0"); } this.loadFactor = loadFactor; this.table = new Entry[initialCapacity]; this.threshold = (int) (initialCapacity * loadFactor); this.queue = new ReferenceQueue(); }
From source file:org.apache.ojb.broker.util.ReferenceMap.java
/** * Reads the contents of this object from the given input stream. * * @param inp the input stream to read from * @throws java.io.IOException if the stream raises it * @throws java.lang.ClassNotFoundException if the stream raises it *//*from w w w . j a va2s. co m*/ private void readObject(ObjectInputStream inp) throws IOException, ClassNotFoundException { inp.defaultReadObject(); table = new Entry[inp.readInt()]; threshold = (int) (table.length * loadFactor); queue = new ReferenceQueue(); Object key = inp.readObject(); while (key != null) { Object value = inp.readObject(); put(key, value); key = inp.readObject(); } }
From source file:WeakSet.java
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream obtis) throws IOException, ClassNotFoundException { obtis.defaultReadObject();// w w w .ja va 2 s.c o m Object[] arr = (Object[]) obtis.readObject(); entries = new Entry[(int) (size * 1.5)]; refq = new ReferenceQueue<E>(); for (int i = 0; i < arr.length; i++) { add((E) arr[i]); } }
From source file:org.apache.sling.models.impl.ModelAdapterFactory.java
@Activate protected void activate(final ComponentContext ctx) { Dictionary<?, ?> props = ctx.getProperties(); final int maxRecursionDepth = PropertiesUtil.toInteger(props.get(PROP_MAX_RECURSION_DEPTH), DEFAULT_MAX_RECURSION_DEPTH); this.invocationCountThreadLocal = new ThreadLocal<ThreadInvocationCounter>() { @Override// w w w.j a v a2s . com protected ThreadInvocationCounter initialValue() { return new ThreadInvocationCounter(maxRecursionDepth); } }; BundleContext bundleContext = ctx.getBundleContext(); this.queue = new ReferenceQueue<Object>(); this.disposalCallbacks = new ConcurrentHashMap<java.lang.ref.Reference<Object>, DisposalCallbackRegistryImpl>(); Hashtable<Object, Object> properties = new Hashtable<Object, Object>(); properties.put(Constants.SERVICE_VENDOR, "Apache Software Foundation"); properties.put(Constants.SERVICE_DESCRIPTION, "Sling Models OSGi Service Disposal Job"); properties.put("scheduler.concurrent", false); properties.put("scheduler.period", 30L); this.jobRegistration = bundleContext.registerService(Runnable.class.getName(), this, properties); this.listener = new ModelPackageBundleListener(ctx.getBundleContext(), this, this.adapterImplementations); Hashtable<Object, Object> printerProps = new Hashtable<Object, Object>(); printerProps.put(Constants.SERVICE_VENDOR, "Apache Software Foundation"); printerProps.put(Constants.SERVICE_DESCRIPTION, "Sling Models Configuration Printer"); printerProps.put("felix.webconsole.label", "slingmodels"); printerProps.put("felix.webconsole.title", "Sling Models"); printerProps.put("felix.webconsole.configprinter.modes", "always"); this.configPrinterRegistration = bundleContext.registerService(Object.class.getName(), new ModelConfigurationPrinter(this), printerProps); }