Package java.lang.ref

Examples of java.lang.ref.ReferenceQueue.poll()


        && ((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));
  }

  /**
   * @tests java.lang.ref.Reference#enqueue()
   */
 
View Full Code Here


                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());
View Full Code Here

    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());
  }

  protected void setUp() {
View Full Code Here

                // eat  a lot of memory so it gets garbage collected quickly
                // (or quickly runs out of memory)
                Node n = s.getRootNode().addNode("n" + i);
                n.setProperty("x", new String(new char[1000000]));
                list.add(new WeakReference(s, detect));
                if (detect.poll() != null) {
                    break;
                }
            }
        } catch (OutOfMemoryError e) {
            error = e;
View Full Code Here

        objectUnderTest_.add(o1);

        o1 = null;

        while (queue.poll() == null && System.currentTimeMillis() < now + 5000)
        {
            System.gc();
        }
       
        assertTrue(objectUnderTest_.isEmpty());
View Full Code Here

    System.out.println("b: " + br.get());
    System.out.println("d: " + dr.get());
    System.out.println("e: " + er.get());
    System.out.println("f: " + map.get(new Key("foo")));

    for (Reference r = q.poll(); r != null; r = q.poll()) {
      System.out.println("polled: " + r.get());     
    }
  }

  private static class MyReference extends WeakReference {
View Full Code Here

    System.out.println("b: " + br.get());
    System.out.println("d: " + dr.get());
    System.out.println("e: " + er.get());
    System.out.println("f: " + map.get(new Key("foo")));

    for (Reference r = q.poll(); r != null; r = q.poll()) {
      System.out.println("polled: " + r.get());     
    }
  }

  private static class MyReference extends WeakReference {
View Full Code Here

    private void cleanup() {
        // Cleanup after cleared References.
        Entry[] tab = this.table;
        ReferenceQueue queue = this.queue;
        Reference ref;
        while ((ref = queue.poll()) != null) {
            // Since buckets are single-linked, traverse entire list and
            // cleanup all cleared references in it.
            int index = (((Entry) ref).hash & 0x7fffffff) % tab.length;
            for (Entry e = tab[index], prev = null; e != null; e = e.next) {
                if (e.get() == null) {
View Full Code Here

        // Cleanup after cleared References.
        {
            ReferenceQueue queue = this.queue;
            Reference ref;
            while ((ref = queue.poll()) != null) {
                // Since buckets are single-linked, traverse entire list and
                // cleanup all cleared references in it.
                int index = (((Entry) ref).hash & 0x7fffffff) % tab.length;
                for (Entry<T> e = tab[index], prev = null; e != null; e = e.next) {
                    if (e.get() == null) {
View Full Code Here

        // some JVMs seem to take a little time to put references on
        // the reference queue once the reference has been collected
        // need to think about whether this is enough to justify
        // stepping through the collection each time...
        while(testQueue.poll() == null) {}

        // Test that the released objects are not taking space in the table
        assertEquals("underlying table not emptied", 0, weakHashtable.size());
    }
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.