Package java.lang.ref

Examples of java.lang.ref.SoftReference


    // generate the tangent table used in IHStoRGB for byte type
    private synchronized void generateTanTable() {
        if ((tanSoftRef == null) || (tanSoftRef.get() == null)) {
            tanTable = new double[256] ;
            tanSoftRef = new SoftReference(tanTable);

            for (int i = 0; i < 256; i++)
                tanTable[i] = Math.tan(i * PI2 / 255.0) ;
        }
    }
View Full Code Here


  if (softRef == null ||
            ((colorConvertOpBuf = (HashMap)softRef.get()) == null)) {

      colorConvertOpBuf = new HashMap();
      softRef = new SoftReference(colorConvertOpBuf);
  }

  ArrayList hashcode = new ArrayList(2);
  hashcode.add(0, src);
  hashcode.add(1, dst);
View Full Code Here

      throw new NullPointerException( "Key to get cannot be null" );
    }

    clearObsoleteReferences();

    SoftReference ref = (SoftReference) softRefCache.get( key );
    if ( ref != null ) {
      Object refValue = ref.get();
      if ( refValue != null ) {
        // This ensures recently used entries are strongly-reachable
        strongRefCache.put( key, refValue );
        return refValue;
      }
View Full Code Here

    }

    clearObsoleteReferences();

    strongRefCache.put( key, value );
    SoftReference ref = (SoftReference) softRefCache.put(
        key,
        new KeyedSoftReference( key, value, referenceQueue )
    );

    return ( ref != null ) ? ref.get() : null;
  }
View Full Code Here

            return value;
        }

        public void put(String key, Object value) {
            if (value != null) {
                CACHE.put(prefix + key, new SoftReference(value));
            }
            else
                CACHE.remove(prefix + key);
            expiryTime = -1;
        }
View Full Code Here

        }

        public void put(String key, Object value, long timeToLive) {
            if (value != null) {
                expiryTime = System.currentTimeMillis() + timeToLive*1000;
                CACHE.put(prefix + key, new SoftReference(value));
            }
            else {
                CACHE.remove(prefix + key);
                expiryTime = -1;
            }
View Full Code Here

                // we're using the parser only as an XNI-to-SAX converter,
                // so that we can use the SAX-based serializer
                SAXParser parser = (SAXParser) fParser.get();
                if (newConfig || parser == null) {
                    parser = new SAXParser(config);
                    fParser = new SoftReference(parser);
                }
                else {
                    parser.reset();
                }
                config.setDocumentHandler(fSchemaValidator);
View Full Code Here

        config.setProperty(VALIDATION_MANAGER, fComponentManager.getProperty(VALIDATION_MANAGER));
        config.setProperty(SECURITY_MANAGER, fComponentManager.getProperty(SECURITY_MANAGER));
        config.setDocumentHandler(fSchemaValidator);
        config.setDTDHandler(null);
        config.setDTDContentModelHandler(null);
        fConfiguration = new SoftReference(config);
        return config;
    }
View Full Code Here

            // create new validator - we should not attempt
            // to restrict the number of validation handlers being
            // requested
            while (freeSchemaValidatorIndex >= 0) {
                // return first available validator
                SoftReference ref = schemaValidators[freeSchemaValidatorIndex];
                RevalidationHandlerHolder holder = (RevalidationHandlerHolder) ref.get();
                if (holder != null && holder.handler != null) {
                    RevalidationHandler val = holder.handler;
                    holder.handler = null;
                    --freeSchemaValidatorIndex;
                    return val;
                }
                schemaValidators[freeSchemaValidatorIndex--] = null;
            }
            //MF
            return (RevalidationHandler) (ObjectFactory
                    .newInstance(
                        "mf.org.apache.xerces.impl.xs.XMLSchemaValidator",
                        ObjectFactory.findClassLoader(),
                        true));
        }
        else if(schemaType == XMLGrammarDescription.XML_DTD) {
            // return an instance of XML11DTDValidator
            if ("1.1".equals(xmlVersion)) {
                while (freeXML11DTDValidatorIndex >= 0) {
                    // return first available validator
                    SoftReference ref = xml11DTDValidators[freeXML11DTDValidatorIndex];
                    RevalidationHandlerHolder holder = (RevalidationHandlerHolder) ref.get();
                    if (holder != null && holder.handler != null) {
                        RevalidationHandler val = holder.handler;
                        holder.handler = null;
                        --freeXML11DTDValidatorIndex;
                        return val;
                    }
                    xml11DTDValidators[freeXML11DTDValidatorIndex--] = null;
                }
                //MF
                return (RevalidationHandler) (ObjectFactory
                        .newInstance(
                                "mf.org.apache.xerces.impl.dtd.XML11DTDValidator",
                                ObjectFactory.findClassLoader(),
                                true));
            }
            // return an instance of XMLDTDValidator
            else {
                while (freeXML10DTDValidatorIndex >= 0) {
                    // return first available validator
                    SoftReference ref = xml10DTDValidators[freeXML10DTDValidatorIndex];
                    RevalidationHandlerHolder holder = (RevalidationHandlerHolder) ref.get();
                    if (holder != null && holder.handler != null) {
                        RevalidationHandler val = holder.handler;
                        holder.handler = null;
                        --freeXML10DTDValidatorIndex;
                        return val;
View Full Code Here

      if (schemaType == XMLGrammarDescription.XML_SCHEMA) {
          ++freeSchemaValidatorIndex;
          if (schemaValidators.length == freeSchemaValidatorIndex) {
              // resize size of the validators
              schemaValidatorsCurrentSize += SIZE;
              SoftReference newarray[] new SoftReference[schemaValidatorsCurrentSize];
              System.arraycopy(schemaValidators, 0, newarray, 0, schemaValidators.length);
              schemaValidators = newarray;
          }
          SoftReference ref = schemaValidators[freeSchemaValidatorIndex];
          if (ref != null) {
              RevalidationHandlerHolder holder = (RevalidationHandlerHolder) ref.get();
              if (holder != null) {
                  holder.handler = validator;
                  return;
              }
          }
          schemaValidators[freeSchemaValidatorIndex] = new SoftReference(new RevalidationHandlerHolder(validator));
      }
      else if (schemaType == XMLGrammarDescription.XML_DTD) {
          // release an instance of XML11DTDValidator
          if ("1.1".equals(xmlVersion)) {
              ++freeXML11DTDValidatorIndex;
              if (xml11DTDValidators.length == freeXML11DTDValidatorIndex) {
                  // resize size of the validators
                  xml11DTDValidatorsCurrentSize += SIZE;
                  SoftReference [] newarray = new SoftReference[xml11DTDValidatorsCurrentSize];
                  System.arraycopy(xml11DTDValidators, 0, newarray, 0, xml11DTDValidators.length);
                  xml11DTDValidators = newarray;
              }
              SoftReference ref = xml11DTDValidators[freeXML11DTDValidatorIndex];
              if (ref != null) {
                  RevalidationHandlerHolder holder = (RevalidationHandlerHolder) ref.get();
                  if (holder != null) {
                      holder.handler = validator;
                      return;
                  }
              }
              xml11DTDValidators[freeXML11DTDValidatorIndex] = new SoftReference(new RevalidationHandlerHolder(validator));
          }
          // release an instance of XMLDTDValidator
          else {
              ++freeXML10DTDValidatorIndex;
              if (xml10DTDValidators.length == freeXML10DTDValidatorIndex) {
                  // resize size of the validators
                  xml10DTDValidatorsCurrentSize += SIZE;
                  SoftReference [] newarray = new SoftReference[xml10DTDValidatorsCurrentSize];
                  System.arraycopy(xml10DTDValidators, 0, newarray, 0, xml10DTDValidators.length);
                  xml10DTDValidators = newarray;
              }
              SoftReference ref = xml10DTDValidators[freeXML10DTDValidatorIndex];
              if (ref != null) {
                  RevalidationHandlerHolder holder = (RevalidationHandlerHolder) ref.get();
                  if (holder != null) {
                      holder.handler = validator;
                      return;
                  }
              }
              xml10DTDValidators[freeXML10DTDValidatorIndex] = new SoftReference(new RevalidationHandlerHolder(validator));
          }
      }
  }
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.