public void run() { while (true) try { // collect next item from cache, // limit 10000 ms is to keep periodically checking if recman was GCed SoftCacheEntry e = (SoftCacheEntry) entryQueue.remove(10000); // check if recman was GCed, cancel in that case CacheRecordManager recman = recman2.get(); if (recman == null) return; if (e != null) { synchronized (recman._softHash) { while (e != null) { recman._softHash.remove(e._recid); e = (SoftCacheEntry) entryQueue.poll(); } } } } catch (InterruptedException e) { return; } catch (Throwable e) { // this thread must keep spinning, // otherwise SoftCacheEntries would not be disposed e.printStackTrace(); } }
public void run() { try { final java.lang.ref.Reference<? extends Object> ref = REAPER_QUEUE.remove(); if (ref instanceof Reapable) { reap((Reapable<?, ?>) ref); } } catch (InterruptedException e) { // ignored } }
@Override public void run() { while (isRunning()) { // Take a reference, blocking until one is ready or the thread should stop try { doFinalize((FinalizerReference<?>) queue.remove()); } catch (InterruptedException ignored) { } } }
@Override public void run() { try { while (isRunning()) { @SuppressWarnings("unchecked") LeakInfo leakInfo = (LeakInfo) queue.remove(); if (LOG.isDebugEnabled()) LOG.debug("Resource GC'ed: {}", leakInfo); if (resources.remove(leakInfo.id) != null) leaked(leakInfo); } } catch (InterruptedException x) { // Exit } }
private static void gc() throws InterruptedException { ReferenceQueue<Object> referenceQueue = new ReferenceQueue<Object>(); WeakReference<Object> weakReference = new WeakReference<Object>(new Object(), referenceQueue); while (weakReference.get() != null) { System.gc(); System.runFinalization(); } Assert.assertSame(weakReference, referenceQueue.remove()); }
@Override public void run() { while (true) { try { Reference<? extends Object> reference = _referenceQueue.remove(); FinalizeAction finalizeAction = _referenceActionMap.remove(reference); finalizeAction.doFinalize(); } catch (InterruptedException ie) { } } }
/** Loops continuously, pulling references off the queue and cleaning them up. */ @SuppressWarnings("InfiniteLoopStatement") @Override public void run() { while (true) { try { if (!cleanUp(queue.remove())) { break; } } catch (InterruptedException e) { // ignore } } }
public void run() { while (true) { try { PhantomWrapper ref = (PhantomWrapper) mQueue.remove(); // System.out.println("dequeued ref " + ref.mNativeData + // " - " + ref); Bitmap.freeNativeStorage(ref.mNativeData); // ref.clear(); } catch (InterruptedException ie) { System.out.println("intr"); break; } } }
/** * Garbage-collection thread: Polls {@link #closedConnectionsQueue} for connections whose {@link * WeakReference} has been nulled and removes them from the {@link #connectionsByID} {@link * TreeMap}.<br> * <br> * Notice: Do not call this function directly. To execute this, call {@link #start()}. This * function is merely public because this class extends {@link NativeThread}. */ @Override public void realRun() { while (true) { try { ConnectionWeakReference closedConnection = (ConnectionWeakReference) closedConnectionsQueue.remove(); connectionsByIDLock.writeLock().lock(); try { ConnectionWeakReference removedFromTree = connectionsByID.remove(closedConnection.connectionID); assert (closedConnection == removedFromTree); if (logMINOR) { Logger.minor( this, "Garbage-collecting closed connection: " + "remaining connections = " + connectionsByID.size() + "; connection ID = " + closedConnection.connectionID); } } finally { connectionsByIDLock.writeLock().unlock(); } } catch (InterruptedException e) { // We did setDaemon(true), which causes the JVM to exit even if the thread is still // running: Daemon threads are force terminated during shutdown. // Thus, this thread does not need an exit mechanism, it can be an infinite loop. So // nothing should try to terminate it by InterruptedException. If it does happen // nevertheless, we honor it by exiting the thread, because interrupt requests // should never be ignored, but log it as an error. Logger.error(this, "Thread interruption requested even though this is a daemon thread!", e); throw new RuntimeException(e); } catch (Throwable t) { Logger.error(this, "Error in thread " + getName(), t); } } }
public static void main(String[] args) { System.err.println("\nRegression test for bug 4404702\n"); /* * HACK: Work around the fact that java.util.logging.LogManager's * (singleton) construction also has this bug-- it will register a * "shutdown hook", i.e. a thread, which will inherit and pin the * current thread's context class loader for the lifetime of the VM-- * by causing the LogManager to be initialized now, instead of by * RMI when our special context class loader is set. */ java.util.logging.LogManager.getLogManager(); /* * HACK: Work around the fact that the non-native, thread-based * SecureRandom seed generator (ThreadedSeedGenerator) seems to * have this bug too (which had been causing this test to fail * when run with jtreg on Windows XP-- see 4910382). */ (new java.security.SecureRandom()).nextInt(); RuntimeThreadInheritanceLeak obj = new RuntimeThreadInheritanceLeak(); try { ClassLoader loader = URLClassLoader.newInstance(new URL[0]); ReferenceQueue refQueue = new ReferenceQueue(); Reference loaderRef = new WeakReference(loader, refQueue); System.err.println("created loader: " + loader); Thread.currentThread().setContextClassLoader(loader); UnicastRemoteObject.exportObject(obj); Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); System.err.println("exported remote object with loader as context class loader"); loader = null; System.err.println("nulled strong reference to loader"); UnicastRemoteObject.unexportObject(obj, true); System.err.println("unexported remote object"); /* * HACK: Work around the fact that the sun.misc.GC daemon thread * also has this bug-- it will have inherited our loader as its * context class loader-- by giving it a chance to pass away. */ Thread.sleep(2000); System.gc(); System.err.println("waiting to be notified of loader being weakly reachable..."); Reference dequeued = refQueue.remove(TIMEOUT); if (dequeued == null) { System.err.println("TEST FAILED: loader not deteced weakly reachable"); dumpThreads(); throw new RuntimeException("TEST FAILED: loader not detected weakly reachable"); } System.err.println("TEST PASSED: loader detected weakly reachable"); dumpThreads(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("TEST FAILED: unexpected exception", e); } finally { try { UnicastRemoteObject.unexportObject(obj, true); } catch (RemoteException e) { } } }