Examples of PhantomReference


Examples of java.lang.ref.PhantomReference

     * @param obj the object on which to wait
     */
    public WaitUnreachable(Object obj) {
        this.obj = obj;
        queue = new ReferenceQueue();
        ref = new PhantomReference(obj, queue);
    }
View Full Code Here

Examples of java.lang.ref.PhantomReference

     * @param obj the object on which to wait
     */
    public WaitUnreachable(Object obj) {
        this.obj = obj;
        queue = new ReferenceQueue();
        ref = new PhantomReference(obj, queue);
    }
View Full Code Here

Examples of java.lang.ref.PhantomReference

     * @param interceptor ignored
     * @param connectionInfo the connection that was released
     * @param action ignored
     */
    public void handleReleased(ConnectionTrackingInterceptor interceptor, ConnectionInfo connectionInfo, ConnectionReturnAction action) {
        PhantomReference phantomReference = references.remove(connectionInfo.getManagedConnectionInfo());
        if (phantomReference != null) {
            phantomReference.clear();
        }
    }
View Full Code Here

Examples of java.lang.ref.PhantomReference

    static boolean passed = false;

    public static void main(String[] args) {
        final ReferenceQueue queue = new ReferenceQueue();
        final Reference ref = new PhantomReference(new PhantomReferenceTest(), queue);
        System.gc();
        Thread x = new Thread() {
            public void run() {
                try {
                    queue.remove();
View Full Code Here

Examples of java.lang.ref.PhantomReference

    static Reference ref;

    public static void main(String[] args) throws Exception {
        ReferenceQueue queue = new ReferenceQueue();
        Object referent = new PhantomReferenceTest();
        ref = new PhantomReference(referent, queue);

        // drop strong reference
        referent = null;

        System.gc();
View Full Code Here

Examples of java.lang.ref.PhantomReference

public class RefRemove {

    public static void main(String[] args) throws Exception {
        ReferenceQueue queue = new ReferenceQueue();
        Object o = new RefRemove();
        Reference ref = new PhantomReference(o, queue);
        o = null;
        System.gc();
        System.err.println("waiting for a reference..");
        Reference enqueued = queue.remove();
        if (enqueued == ref) {
View Full Code Here

Examples of java.lang.ref.PhantomReference

   * @tests java.lang.ref.PhantomReference#get()
   */
  public void test_get() {
    ReferenceQueue rq = new ReferenceQueue();
    bool = new Boolean(false);
    PhantomReference pr = new PhantomReference(bool, rq);
    assertNull("Same object returned.", pr.get());
  }
View Full Code Here

Examples of java.lang.ref.PhantomReference

   *        java.lang.ref.ReferenceQueue)
   */
  public void test_ConstructorLjava_lang_ObjectLjava_lang_ref_ReferenceQueue() throws Exception {
    ReferenceQueue rq = new ReferenceQueue();
    bool = new Boolean(true);
                PhantomReference pr = new PhantomReference(bool, rq);
                // Allow the finalizer to run to potentially enqueue
                Thread.sleep(1000);
                assertTrue("Initialization failed.", !pr.isEnqueued());

                // need a reference to bool so the jit does not optimize it away
    assertTrue("should always pass", bool.booleanValue());

    boolean exception = false;
    try {
      new PhantomReference(bool, null);
    } catch (NullPointerException e) {
      exception = true;
    }
    assertTrue("Should not throw NullPointerException", !exception);
  }
View Full Code Here

Examples of java.lang.ref.PhantomReference

public class RefRemove {

    public static void main(String[] args) throws Exception {
        ReferenceQueue queue = new ReferenceQueue();
        Object o = new RefRemove();
        Reference ref = new PhantomReference(o, queue);
        o = null;
        System.gc();
        System.err.println("waiting for a reference..");
        Reference enqueued = queue.remove();
        if (enqueued == ref) {
View Full Code Here

Examples of java.lang.ref.PhantomReference

    static boolean passed = false;

    public static void main(String[] args) {
        final ReferenceQueue queue = new ReferenceQueue();
        final Reference ref = new PhantomReference(new PhantomReferenceTest(), queue);
        System.gc();
        Thread x = new Thread() {
            public void run() {
                try {
                    queue.remove();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.