Examples of WeakReference


Examples of java.lang.ref.WeakReference

   *
   * @param uri DOCUMENT ME!
   * @return the name model for the given name and namepsace
   */
  public Namespace get(String uri) {
    WeakReference ref = (WeakReference) noPrefixCache.get(uri);
    Namespace answer = null;

    if (ref != null) {
      answer = (Namespace) ref.get();
    }

    if (answer == null) {
      synchronized (noPrefixCache) {
        ref = (WeakReference) noPrefixCache.get(uri);

        if (ref != null) {
          answer = (Namespace) ref.get();
        }

        if (answer == null) {
          answer = createNamespace("", uri);
          noPrefixCache.put(uri, new WeakReference(answer));
        }
      }
    }

    return answer;
View Full Code Here

Examples of java.lang.ref.WeakReference

  }

  public Object instance() {
    Object singletonInstancePerThread = null;
    // use weak reference to prevent cyclic reference during GC
    WeakReference ref = (WeakReference) perThreadCache.get();
    // singletonInstancePerThread=perThreadCache.get();
    // if (singletonInstancePerThread==null) {
    if (ref == null || ref.get() == null) {
      Class clazz = null;
      try {
        clazz = Thread.currentThread().getContextClassLoader().loadClass(
            singletonClassName);
        singletonInstancePerThread = clazz.newInstance();
      } catch (Exception ignore) {
        try {
          clazz = Class.forName(singletonClassName);
          singletonInstancePerThread = clazz.newInstance();
        } catch (Exception ignore2) {
        }
      }
      perThreadCache.set(new WeakReference(singletonInstancePerThread));
    } else {
      singletonInstancePerThread = ref.get();
    }
    return singletonInstancePerThread;
  }
View Full Code Here

Examples of java.lang.ref.WeakReference

  
   /** @param callback The handle to callback a client (is checked already to be not null) */
   Container(boolean useWeakReference, I_Timeout callback, Object userData) {
      this.useWeakReference = useWeakReference;
      if (this.useWeakReference) {
         this.callback = new WeakReference(callback);
         if (userData != null)
            this.userData = new WeakReference(userData);
      }
      else {
         this.callback = callback;
         this.userData = userData;
      }
View Full Code Here

Examples of java.lang.ref.WeakReference

   }

   /** @return The callback handle can be null for weak references */
   I_Timeout getCallback() {
      if (this.useWeakReference) {
         WeakReference weak = (WeakReference)this.callback;
         return (I_Timeout)weak.get();
      }
      else {
         return (I_Timeout)this.callback;
      }
   }
View Full Code Here

Examples of java.lang.ref.WeakReference

   Object getUserData() {
      if (this.userData == null) {
         return null;
      }
      if (this.useWeakReference) {
         WeakReference weak = (WeakReference)this.userData;
         return weak.get();
      }
      else {
         return this.userData;
      }
   }
View Full Code Here

Examples of java.lang.ref.WeakReference

            this.childs = new HashMap();
         }
         if (doClone) {
            ContextNode clone = child.getClone();
            clone.parent = this;
            this.childs.put(clone.getAbsoluteName(), new WeakReference(clone));
         }
         else {
            if (child.parent != null && this != child.parent) {
               // If child had another parent already remove it
               child.parent.removeChild(child);
            }
            child.parent = this;
            this.childs.put(child.getAbsoluteName(), new WeakReference(child));
         }
      }
      return true;
   }
View Full Code Here

Examples of java.lang.ref.WeakReference

                                                     Component component) {
        // ATTN: component has a strong reference to window via chain
        // of Component.parent fields.  Since WeakHasMap refers to its
        // values strongly, we need to break the strong link from the
        // value (component) back to its key (window).
        WeakReference weakValue = null;
        if (component != null) {
            weakValue = new WeakReference(component);
        }
        mostRecentFocusOwners.put(window, weakValue);
    }
View Full Code Here

Examples of java.lang.ref.WeakReference

    /*
     * Please be careful changing this method! It is called from
     * javax.swing.JComponent.runInputVerifier() using reflection.
     */
    static synchronized Component getMostRecentFocusOwner(Window window) {
        WeakReference weakValue =
            (WeakReference)mostRecentFocusOwners.get(window);
        return weakValue == null ? null : (Component)weakValue.get();
    }
View Full Code Here

Examples of java.lang.ref.WeakReference

    {
        if (Thread.currentThread() != dispatchThread) {
            return;
        }

        currentEvent = new WeakReference(e);

        // This series of 'instanceof' checks should be replaced with a
        // polymorphic type (for example, an interface which declares a
        // getWhen() method). However, this would require us to make such
        // a type public, or to place it in sun.awt. Both of these approaches
View Full Code Here

Examples of java.lang.ref.WeakReference

      // Remove ourself from any previous parent.
      if (parent != null) {
    // assert parent.kids != null;
    for (Iterator iter = parent.kids.iterator(); iter.hasNext(); ) {
        WeakReference ref = (WeakReference) iter.next();
        Logger kid = (Logger) ref.get();
        if (kid == this) {
            iter.remove();
      break;
        }
     }
    // We have now removed ourself from our parents' kids.
      }

      // Set our new parent.
      parent = newParent;
      if (parent.kids == null) {
          parent.kids = new ArrayList(2);
      }
      parent.kids.add(new WeakReference(this));

      // As a result of the reparenting, the effective level
      // may have changed for us and our children.
      updateEffectiveLevel();
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.