Package java.lang.ref

Examples of java.lang.ref.WeakReference


  private static final class SweepTask extends TimerTask {

    private final WeakReference poolRef;

    private SweepTask(Pool pool) {
      this.poolRef = new WeakReference(pool);
    }
View Full Code Here


     */
    public TransactionContext(TransactionRegistry transactionRegistry, Transaction transaction) {
        if (transactionRegistry == null) throw new NullPointerException("transactionRegistry is null");
        if (transaction == null) throw new NullPointerException("transaction is null");
        this.transactionRegistry = transactionRegistry;
        this.transactionRef = new WeakReference(transaction);
    }
View Full Code Here

     */
    protected void registerCursor(Cursor cur) {
        // We take this opportunity to clean the _cursors list
        // of WeakReference objects to garbage-collected cursors.
        for (Iterator it = _cursors.iterator(); it.hasNext(); ) {
            WeakReference ref = (WeakReference) it.next();
            if (ref.get() == null) {
                it.remove();
            }
        }

        _cursors.add( new WeakReference(cur) );
    }
View Full Code Here

     * Removes a {@link CursorableLinkedList.Cursor} from
     * the set of cursors to be notified of changes to this list.
     */
    protected void unregisterCursor(Cursor cur) {
        for (Iterator it = _cursors.iterator(); it.hasNext(); ) {
            WeakReference ref = (WeakReference) it.next();
            Cursor cursor = (Cursor) ref.get();
            if (cursor == null) {
                // some other unrelated cursor object has been
                // garbage-collected; let's take the opportunity to
                // clean up the cursors list anyway..
                it.remove();

            } else if (cursor == cur) {
                ref.clear();
                it.remove();
                break;
            }
        }
    }
View Full Code Here

     * invalid.
     */
    protected void invalidateCursors() {
        Iterator it = _cursors.iterator();
        while (it.hasNext()) {
            WeakReference ref = (WeakReference) it.next();
            Cursor cursor = (Cursor) ref.get();
            if (cursor != null) {
                // cursor is null if object has been garbage-collected
                cursor.invalidate();
                ref.clear();
            }
            it.remove();
        }
    }
View Full Code Here

     * @see #set(int,java.lang.Object)
     */
    protected void broadcastListableChanged(Listable elt) {
        Iterator it = _cursors.iterator();
        while (it.hasNext()) {
            WeakReference ref = (WeakReference) it.next();
            Cursor cursor = (Cursor) ref.get();
            if (cursor == null) {
                it.remove(); // clean up list
            } else {
                cursor.listableChanged(elt);
            }
View Full Code Here

     * element was just removed from my list.
     */
    protected void broadcastListableRemoved(Listable elt) {
        Iterator it = _cursors.iterator();
        while (it.hasNext()) {
            WeakReference ref = (WeakReference) it.next();
            Cursor cursor = (Cursor) ref.get();
            if (cursor == null) {
                it.remove(); // clean up list
            } else {
                cursor.listableRemoved(elt);
            }
View Full Code Here

     * element was just added to my list.
     */
    protected void broadcastListableInserted(Listable elt) {
        Iterator it = _cursors.iterator();
        while (it.hasNext()) {
            WeakReference ref = (WeakReference) it.next();
            Cursor cursor = (Cursor) ref.get();
            if (cursor == null) {
                it.remove()// clean up list
            } else {
                cursor.listableInserted(elt);
            }
View Full Code Here

        // Refer to the log stream via a weak reference so that this thread
        // doesn't prevent it from being garbage collected.
        private WeakReference mLogStream;

        public AutoRollover(IntervalLogStream stream) {
            mLogStream = new WeakReference(stream);
        }
View Full Code Here

    public Log(String name, Log parent) {
        this();

        if (parent != null) {
            mParent = parent;
            parent.mChildren.add(new WeakReference(this));
            mEnabledFlags = parent.mEnabledFlags;
            addLogListener(parent);
        }

        mName = name;
View Full Code Here

TOP

Related Classes of java.lang.ref.WeakReference

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.