Package java.lang.ref

Examples of java.lang.ref.WeakReference


    Class c = null;
    synchronized (peersLoaders)
    {
      for (int i = 0; i < peersLoaders.size() && c == null; i++)
      {
        WeakReference ref = (WeakReference) peersLoaders.get(i);
        SecondaryClassLoader loader = (SecondaryClassLoader) ref.get();
        if (loader != null)
          c = loader.findLoadedClassHelper(className);
        else
          peersLoaders.remove(i--);
      }
View Full Code Here


    Class c = null;
    synchronized (peersLoaders)
    {
      for(int i=0;i<peersLoaders.size()&&c==null;i++)
      {
        WeakReference ref = (WeakReference)peersLoaders.get(i);
        SecondaryClassLoader loader = (SecondaryClassLoader)ref.get();
        if(loader != null) // no removal here, peerFindLoadedClass should take care of that anyway
          c = loader.findClassHelper(className);
      }
     
    }
View Full Code Here

 
  void registerSecondaryClassloader(SecondaryClassLoader loader)
  {
    synchronized (peersLoaders)
    {
      peersLoaders.add(new WeakReference(loader));
    }
   
  }
View Full Code Here

        public int refcount = 1; // has ref count of one at creation
        public WeakReference manager;
       
        public ReferenceCountedPointer(ListenerManager mgr, Object o) {
            super(o);
            manager = new WeakReference(mgr);
        }
View Full Code Here

   /**
    * @param testsuite If != null your update() variant will be called as well
    */
   public MsgInterceptor(Global glob, Logger log, I_Callback testsuite) {
      this.weakglob = new WeakReference(glob);
      this.weaklog = new WeakReference(log);
      this.testsuite = testsuite;
      //this.msgs = new Msgs();
   }
View Full Code Here

      }
      if (referent == null || ((MsgUnitWrapper)referent).isSwapped()) {  // message was swapped away
         this.weakMsgUnitWrapper = null;
         referent = lookup();
         if (referent == null) return null;
         this.weakMsgUnitWrapper = new WeakReference(referent);
      }
      MsgUnitWrapper msgUnitWrapper = (MsgUnitWrapper)referent;
      if (msgUnitWrapper == null) {
         if (!isForceDestroy()) {
            log.severe(getInfoWithoutMeat()+" No meat found but forceDestroy=false " + Global.getStackTraceAsString(null));
View Full Code Here

   }

   public void setMsgUnitWrapper(MsgUnitWrapper msgUnitWrapper) throws XmlBlasterException {
      if (msgUnitWrapper == null)
         throw new XmlBlasterException(glob, ErrorCode.INTERNAL_ILLEGALARGUMENT, ME, "Given msgUnitWrapper is null");
      this.weakMsgUnitWrapper = new WeakReference(msgUnitWrapper);
      this.keyOid = msgUnitWrapper.getMsgUnit().getKeyData().getOid();
      this.msgUnitWrapperUniqueId = msgUnitWrapper.getUniqueId();
   }
View Full Code Here

   * @param uri    DOCUMENT ME!
   * @return the namespace for the given prefix and uri
   */
  public Namespace get(String prefix, String uri) {
    Map uriCache = getURICache(uri);
    WeakReference ref = (WeakReference) uriCache.get(prefix);
    Namespace answer = null;

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

    if (answer == null) {
      synchronized (uriCache) {
        ref = (WeakReference) uriCache.get(prefix);

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

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

    return answer;
View Full Code Here

   *
   * @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

  }

  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

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.