Package java.lang.ref

Examples of java.lang.ref.SoftReference


   * @return a cached instance
   */
  public static SimpleFontExtensionHelper getInstance()
  {
    SimpleFontExtensionHelper instance = null;
    SoftReference instanceRef = (SoftReference) threadInstances.get();
    if (instanceRef != null)
    {
      instance = (SimpleFontExtensionHelper) instanceRef.get();
    }
    if (instance == null)
    {
      instance = new SimpleFontExtensionHelper();
      threadInstances.set(new SoftReference(instance));
    }
    return instance;
  }
View Full Code Here


   * @return a cached instance
   */
  public static JRStyledTextParser getInstance()
  {
    JRStyledTextParser instance = null;
    SoftReference instanceRef = (SoftReference) threadInstances.get();
    if (instanceRef != null)
    {
      instance = (JRStyledTextParser) instanceRef.get();
    }
    if (instance == null)
    {
      instance = new JRStyledTextParser();
      threadInstances.set(new SoftReference(instance));
    }
    return instance;
  }
View Full Code Here

                    // Use the same loader, allowing the new class access to
                    // same package protected members.
                    loader = (Loader) parent;
                    break getLoader;
                }
                SoftReference ref = (SoftReference) cLoaders.get(parent);
                if (ref != null) {
                    loader = (Loader) ref.get();
                    if (loader != null && loader.isValid()) {
                        break getLoader;
                    }
                    ref.clear();
                }
                loader = parent == null ? new Loader() : new Loader(parent);
                cLoaders.put(parent, new SoftReference(loader));
            }

            if (explicit) {
                reserveCheck: {
                    for (int i=0; i<2; i++) {
                        if (loader.reserveName(name)) {
                            try {
                                loader.loadClass(name);
                            } catch (ClassNotFoundException e) {
                                break reserveCheck;
                            }
                        }
                        if (i > 0) {
                            throw new IllegalStateException
                                ("Class name already reserved: " + name);
                        }
                        // Make a new loader and try again.
                        loader = parent == null ? new Loader() : new Loader(parent);
                    }

                    // Save new loader.
                    cLoaders.put(parent, new SoftReference(loader));
                }
            } else {
                for (int tryCount = 0; tryCount < 1000; tryCount++) {
                    name = null;
                   
View Full Code Here

   
    private synchronized XMLInputFactory getInputFactory() {
      XMLInputFactory inputFactory = (XMLInputFactory) factoryRef.get();
      if (inputFactory == null) {
        inputFactory = createInputFactory();
        factoryRef = new SoftReference(inputFactory);
      }
      return inputFactory;
    }
View Full Code Here

//    }
   
    Map methods = (Map) ENCODING_METHODS.get();
    if (methods == null) {
      methods = Collections.synchronizedMap(new HashMap());
      ENCODING_METHODS = new SoftReference(methods);
    }

    Method method = (Method) methods.get(writer.getClass().getName());
    if (method == null) { // not yet cached?
      method = NOT_AVAILABLE;
View Full Code Here

      log.debug("putFile: " + file.getName());
    }

    Map files = getOrCreateFilesystemCache(file.getFileSystem());

    Reference ref = new SoftReference(file, refqueue);
    FileSystemAndNameKey key = new FileSystemAndNameKey(file
        .getFileSystem(), file.getName());

    synchronized (files)
    {
View Full Code Here

  {
    Map files = getOrCreateFilesystemCache(filesystem);

    synchronized (files)
    {
      SoftReference ref = (SoftReference) files.get(name);
      if (ref == null)
      {
        return null;
      }

      FileObject fo = (FileObject) ref.get();
      if (fo == null)
      {
        removeFile(filesystem, name);
      }
      return fo;
View Full Code Here

  public void set(Object value) {
    super.set(wrap(value));
  }
 
  private static SoftReference wrap(Object value) {
    return new SoftReference(value);
  }
View Full Code Here

    public void set(Object value) {
      super.set(wrap(value));
    }
   
    private static SoftReference wrap(Object value) {
      return new SoftReference(value);
    }
View Full Code Here

                } else {
                    newlyCreated = true;
                    obj = _factory.makeObject();
                }
            } else {
                SoftReference ref = (SoftReference)(_pool.remove(_pool.size() - 1));
                obj = ref.get();
                ref.clear(); // prevent this ref from being enqueued with refQueue.
            }
            if (null != _factory && null != obj) {
                try {
                    _factory.activateObject(obj);
                    if (!_factory.validateObject(obj)) {
View Full Code Here

TOP

Related Classes of java.lang.ref.SoftReference

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.