public BufferSoftReference(ByteBuffer referent) { super(referent, WeakCollectionCleaner.DEFAULT.getReferenceQueue()); }
/** * Hook to cleanup various stuff of some used libraries (org.geotools), which depend on the * external client to call them for cleaning-up. */ private void cleanupWebapp() { LOG.info("Web application shutdown: cleaning various stuff"); WeakCollectionCleaner.DEFAULT.exit(); DeferredAuthorityFactory.exit(); }
/** * Stops the cleaner thread. Calling this method is recommended in all long running applications * with custom class loaders (e.g., web applications). */ public void exit() { // try to stop it gracefully synchronized (this) { referenceQueue = null; } this.interrupt(); try { this.join(500); } catch (InterruptedException e) { } // last resort tentative to kill the cleaner thread if (this.isAlive()) this.stop(); } }
/** * Constructs and starts a new thread as a daemon. This thread will be sleeping most of the * time. It will run only some few nanoseconds each time a new {@link Reference} is enqueded. */ private WeakCollectionCleaner() { super("WeakCollectionCleaner"); setPriority(MAX_PRIORITY - 2); setDaemon(true); start(); }
public void run() { ReferenceQueue<Object> rq; while ((rq = getReferenceQueue()) != null) { try { sleep(15 * 1000L); break;
/** * Returns the value to which this map maps the specified key. Returns {@code null} if the map * contains no mapping for this key. * * @param key Key whose associated value is to be returned. * @return The value to which this map maps the specified key. * @throws NullPointerException if the key is {@code null}. */ @Override public synchronized V get(final Object key) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; final int index = (key.hashCode() & 0x7FFFFFFF) % table.length; for (Entry e = table[index]; e != null; e = e.next) { if (key.equals(e.key)) { return e.get(); } } return null; }
sleep(15 * 1000L); break;
/** * Constructs and starts a new thread as a daemon. This thread will be sleeping * most of the time. It will run only some few nanoseconds each time a new * {@link WeakReference} is enqueded. */ private WeakCollectionCleaner() { super("WeakCollectionCleaner"); setPriority(MAX_PRIORITY - 2); setDaemon(true); start(); }
public void run() { ReferenceQueue<Object> rq; while ((rq = getReferenceQueue ()) != null) { try { sleep(15 * 1000L); break;
final <T extends E> T intern(final T obj, final int operation) { assert Thread.holdsLock(this); assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; if (obj != null) {
public DataStoreSoftReference(DataStore referent) { super(referent, WeakCollectionCleaner.DEFAULT.getReferenceQueue()); }
/** * Constructs and starts a new thread as a daemon. This thread will be sleeping * most of the time. It will run only some few nanoseconds each time a new * {@link Reference} is enqueded. */ private WeakCollectionCleaner() { super("WeakCollectionCleaner"); setPriority(MAX_PRIORITY - 2); setDaemon(true); start(); }
/** * Stops the cleaner thread. Calling this method is recommended in all long running applications * with custom class loaders (e.g., web applications). */ public void exit() { // try to stop it gracefully synchronized (this) { referenceQueue = null; } this.interrupt(); try { this.join(500); } catch (InterruptedException e) { } // last resort tentative to kill the cleaner thread if (this.isAlive()) this.stop(); } }
/** Implementation of {@link #put} and {@link #remove} operations. */ private synchronized V intern(final K key, final V value) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; /* * Check if {@code obj} is already contained in this * {@code WeakValueHashMap}. If yes, clear it. */ V oldValue = null; final int hash = key.hashCode() & 0x7FFFFFFF; int index = hash % table.length; for (Entry e = table[index]; e != null; e = e.next) { if (key.equals(e.key)) { oldValue = e.get(); e.clear(); } } if (value != null) { if (count >= threshold) { rehash(true); } index = hash % table.length; table[index] = new Entry(key, value, table[index], index); count++; } assert valid(); return oldValue; }
WeakCollectionCleaner.DEFAULT.exit(); DeferredAuthorityFactory.exit(); CRS.reset("all");
public DataStoreSoftReference(DataStore referent) { super(referent, WeakCollectionCleaner.DEFAULT.getReferenceQueue()); }
/** * Returns the value to which this map maps the specified key. Returns * {@code null} if the map contains no mapping for this key. * * @param key Key whose associated value is to be returned. * @return The value to which this map maps the specified key. * @throws NullPointerException if the key is {@code null}. */ @Override public synchronized V get(final Object key) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; final int index = (key.hashCode() & 0x7FFFFFFF) % table.length; for (Entry e=table[index]; e!=null; e=e.next) { if (key.equals(e.key)) { return e.get(); } } return null; }
public BufferSoftReference(ByteBuffer referent) { super(referent, WeakCollectionCleaner.DEFAULT.getReferenceQueue()); }
/** * Returns the value to which this map maps the specified key. Returns * {@code null} if the map contains no mapping for this key. * * @param key Key whose associated value is to be returned. * @return The value to which this map maps the specified key. * @throws NullPointerException if the key is {@code null}. */ public synchronized Object get(final Object key) { assert WeakCollectionCleaner.DEFAULT.isAlive(); assert valid() : count; final int index = (key.hashCode() & 0x7FFFFFFF) % table.length; for (Entry e=table[index]; e!=null; e=e.next) { if (key.equals(e.key)) { return e.get(); } } return null; }
public DataStoreSoftReference(DataStore referent) { super(referent, WeakCollectionCleaner.DEFAULT.getReferenceQueue()); }