Package java.lang.ref

Examples of java.lang.ref.Reference$Lock


       
        synchronized (REFERENCE_TO_CONNECTION_SOURCE) {
           
            Iterator referenceIter = REFERENCE_TO_CONNECTION_SOURCE.keySet().iterator();
            while (referenceIter.hasNext()) {
                Reference ref = (Reference) referenceIter.next();
                ConnectionSource source =
                    (ConnectionSource) REFERENCE_TO_CONNECTION_SOURCE.get(ref);
                if (source.connectionPool == connectionPool) {
                    referenceIter.remove();
                    HttpConnection connection = (HttpConnection) ref.get();
                    if (connection != null) {
                        connectionsToClose.add(connection);
                    }
                }
            }
View Full Code Here


    /**
     * If any idle objects were garbage collected, remove their
     * {@link Reference} wrappers from the idle object pool.
     */
    private void pruneClearedReferences() {
        Reference ref;
        while ((ref = refQueue.poll()) != null) {
            try {
                _pool.remove(ref);
            } catch (UnsupportedOperationException uoe) {
                // ignored
View Full Code Here

    try {
      assertNull("Queue is empty.", rq.poll());
      assertNull("Queue is empty.", rq.remove((long) 1));
      Thread ct = new Thread(new ChildThread());
      ct.start();
      Reference ret = rq.remove(0L);
      assertNotNull("Delayed remove failed.", ret);
    } catch (InterruptedException e) {
      fail("InterruptedExeException during test : " + e.getMessage());
    }
    catch (Exception e) {
View Full Code Here

   * @tests java.lang.ref.Reference#enqueue()
   */
  public void test_enqueue() {
    ReferenceQueue rq = new ReferenceQueue();
    obj = new Object();
    Reference ref = new SoftReference(obj, rq);
    assertTrue("Enqueue failed.", (!ref.isEnqueued())
        && ((ref.enqueue()) && (ref.isEnqueued())));
    assertTrue("Not properly enqueued.", rq.poll().get() == obj);
    // This fails...
    assertTrue("Should remain enqueued.", !ref.isEnqueued());
    assertTrue("Can not enqueue twice.", (!ref.enqueue())
        && (rq.poll() == null));

    rq = new ReferenceQueue();
    obj = new Object();
    ref = new WeakReference(obj, rq);
    assertTrue("Enqueue failed2.", (!ref.isEnqueued())
        && ((ref.enqueue()) && (ref.isEnqueued())));
    assertTrue("Not properly enqueued2.", rq.poll().get() == obj);
    assertTrue("Should remain enqueued2.", !ref.isEnqueued()); // This
    // fails.
    assertTrue("Can not enqueue twice2.", (!ref.enqueue())
        && (rq.poll() == null));
  }
View Full Code Here

        wr = new WeakReference(testObj, rq);
        testObj = null;
      }
    }

    Reference ref;

    try {
      Thread t = new TestThread();
      t.start();
      t.join();
      System.gc();
      System.runFinalization();
      ref = rq.remove();
      assertTrue("Unexpected ref1", ref == wr);
      assertNotNull("Object not garbage collected1.", ref);
      assertNull("Object could not be reclaimed1.", wr.get());
    } catch (InterruptedException e) {
      fail("InterruptedException : " + e.getMessage());
    }

    try {
      Thread t = new TestThread();
      t.start();
      t.join();
      System.gc();
      System.runFinalization();
      ref = rq.poll();
      assertTrue("Unexpected ref2", ref == wr);
      assertNotNull("Object not garbage collected.", ref);
      assertNull("Object could not be reclaimed.", ref.get());
      // Reference wr so it does not get collected
      assertNull("Object could not be reclaimed.", wr.get());
    } catch (Exception e) {
      fail("Exception : " + e.getMessage());
    }
View Full Code Here

   * @tests java.lang.ref.Reference#get()
   */
  public void test_get() {
    // SM.
    obj = new Object();
    Reference ref = new WeakReference(obj, new ReferenceQueue());
    assertTrue("Get succeeded.", ref.get() == obj);
  }
View Full Code Here

   * @tests java.lang.ref.Reference#isEnqueued()
   */
  public void test_isEnqueued() {
    ReferenceQueue rq = new ReferenceQueue();
    obj = new Object();
    Reference ref = new SoftReference(obj, rq);
    assertTrue("Should start off not enqueued.", !ref.isEnqueued());
    ref.enqueue();
    assertTrue("Should now be enqueued.", ref.isEnqueued());
    ref.enqueue();
    assertTrue("Should still be enqueued.", ref.isEnqueued());
    rq.poll();
    // This fails ...
    assertTrue("Should now be not enqueued.", !ref.isEnqueued());
  }
View Full Code Here

       
        synchronized (REFERENCE_TO_CONNECTION_SOURCE) {
           
            Iterator referenceIter = REFERENCE_TO_CONNECTION_SOURCE.keySet().iterator();
            while (referenceIter.hasNext()) {
                Reference ref = (Reference) referenceIter.next();
                ConnectionSource source =
                    (ConnectionSource) REFERENCE_TO_CONNECTION_SOURCE.get(ref);
                if (source.connectionPool == connectionPool) {
                    referenceIter.remove();
                    HttpConnection connection = (HttpConnection) ref.get();
                    if (connection != null) {
                        connectionsToClose.add(connection);
                    }
                }
            }
View Full Code Here

            while (!shutdown) {
                try {
                    // remove the next reference and process it, a timeout
                    // is used so that the thread does not block indefinitely
                    // and therefore keep the thread from shutting down
                    Reference ref = REFERENCE_QUEUE.remove(1000);
                    if (ref != null) {
                        handleReference(ref);
                    }
                } catch (InterruptedException e) {
                    LOG.debug("ReferenceQueueThread interrupted", e);
View Full Code Here

    /**
     * If any idle objects were garbage collected, remove their
     * {@link Reference} wrappers from the idle object pool.
     */
    private void pruneClearedReferences() {
        Reference ref;
        while ((ref = refQueue.poll()) != null) {
            try {
                _pool.remove(ref);
            } catch (UnsupportedOperationException uoe) {
                // ignored
View Full Code Here

TOP

Related Classes of java.lang.ref.Reference$Lock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.