當前位置: 首頁>>代碼示例>>Java>>正文


Java SoftReference.get方法代碼示例

本文整理匯總了Java中java.lang.ref.SoftReference.get方法的典型用法代碼示例。如果您正苦於以下問題:Java SoftReference.get方法的具體用法?Java SoftReference.get怎麽用?Java SoftReference.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.ref.SoftReference的用法示例。


在下文中一共展示了SoftReference.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDirectByteBuffer

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private static ByteBuffer getDirectByteBuffer()
{
    // Since direct buffers are allocated outside of the heap they can behave strangely in relation to GC
    // So we try to make them as long-lived as possible and cache them in a ThreadLocal
    ByteBuffer buffer = null;
    int blockSize = getBlockSize();
    SoftReference<ByteBuffer> reference = DiskDataStorage.threadLocal.get();
    if (reference != null)
    {
        buffer = reference.get();
        if (buffer != null && buffer.capacity() != blockSize)
        {
            // Clear references to the direct buffer so it may be GC'd
            reference.clear();
            buffer = null;
        }
    }
    if (buffer == null)
    {
        buffer = ByteBuffer.allocateDirect(blockSize);
        reference = new SoftReference<ByteBuffer>(buffer);
        DiskDataStorage.threadLocal.set(reference);
    }

    return buffer;
}
 
開發者ID:mtommila,項目名稱:apfloat,代碼行數:27,代碼來源:DiskDataStorage.java

示例2: getChars

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public static char[] getChars(int length) {
    SoftReference<char[]> ref = charsBufLocal.get();

    if (ref == null) {
        return allocate(length);
    }

    char[] chars = ref.get();

    if (chars == null) {
        return allocate(length);
    }

    if (chars.length < length) {
        chars = allocate(length);
    }

    return chars;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:ThreadLocalCache.java

示例3: SerializeWriter

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public SerializeWriter(Writer writer, SerializerFeature... features){
    this.writer = writer;

    SoftReference<char[]> ref = bufLocal.get();

    if (ref != null) {
        buf = ref.get();
        bufLocal.set(null);
    }

    if (buf == null) {
        buf = new char[1024];
    }

    int featuresValue = 0;
    for (SerializerFeature feature : features) {
        featuresValue |= feature.getMask();
    }
    this.features = featuresValue;
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:21,代碼來源:SerializeWriter.java

示例4: getEntry

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private Entry getEntry(Object key, GraphicsConfiguration config,
                       int w, int h, Object[] args) {
    Entry entry;
    Iterator<SoftReference<Entry>> iter = entries.listIterator();
    while (iter.hasNext()) {
        SoftReference<Entry> ref = iter.next();
        entry = ref.get();
        if (entry == null) {
            // SoftReference was invalidated, remove the entry
            iter.remove();
        }
        else if (entry.equals(config, w, h, args)) {
            // Put most recently used entries at the head
            iter.remove();
            entries.addFirst(ref);
            return entry;
        }
    }
    // Entry doesn't exist
    entry = new Entry(config, w, h, args);
    if (entries.size() >= maxCount) {
        entries.removeLast();
    }
    entries.addFirst(new SoftReference<Entry>(entry));
    return entry;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:ImageCache.java

示例5: checkProtoHistory

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
/**
 * Check prototype history for an existing property map with specified prototype.
 *
 * @param proto New prototype object.
 *
 * @return Existing {@link PropertyMap} or {@code null} if not found.
 */
private PropertyMap checkProtoHistory(final ScriptObject proto) {
    final PropertyMap cachedMap;
    if (protoHistory != null) {
        final SoftReference<PropertyMap> weakMap = protoHistory.get(proto);
        cachedMap = (weakMap != null ? weakMap.get() : null);
    } else {
        cachedMap = null;
    }

    if (Context.DEBUG && cachedMap != null) {
        protoHistoryHit++;
    }

    return cachedMap;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:PropertyMap.java

示例6: getBundles

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public List<ResourceBundle> getBundles(Locale locale) {
    if (locale == currentLocale && currentBundles != null)
        return currentBundles;
    SoftReference<List<ResourceBundle>> bundles = bundleCache.get(locale);
    List<ResourceBundle> bundleList = bundles == null ? null : bundles.get();
    if (bundleList == null) {
        bundleList = List.nil();
        for (String bundleName : bundleNames) {
            try {
                ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale);
                bundleList = bundleList.prepend(rb);
            } catch (MissingResourceException e) {
                throw new InternalError("Cannot find javac resource bundle for locale " + locale);
            }
        }
        bundleCache.put(locale, new SoftReference<List<ResourceBundle>>(bundleList));
    }
    return bundleList;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:JavacMessages.java

示例7: getDisplayName

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private String getDisplayName(String id, int type, Locale locale) {
    if (textStyle == TextStyle.NARROW) {
        return null;
    }
    String[] names;
    SoftReference<Map<Locale, String[]>> ref = cache.get(id);
    Map<Locale, String[]> perLocale = null;
    if (ref == null || (perLocale = ref.get()) == null ||
        (names = perLocale.get(locale)) == null) {
        names = TimeZoneNameUtility.retrieveDisplayNames(id, locale);
        if (names == null) {
            return null;
        }
        names = Arrays.copyOfRange(names, 0, 7);
        names[5] =
            TimeZoneNameUtility.retrieveGenericDisplayName(id, TimeZone.LONG, locale);
        if (names[5] == null) {
            names[5] = names[0]; // use the id
        }
        names[6] =
            TimeZoneNameUtility.retrieveGenericDisplayName(id, TimeZone.SHORT, locale);
        if (names[6] == null) {
            names[6] = names[0];
        }
        if (perLocale == null) {
            perLocale = new ConcurrentHashMap<>();
        }
        perLocale.put(locale, names);
        cache.put(id, new SoftReference<>(perLocale));
    }
    switch (type) {
    case STD:
        return names[textStyle.zoneNameStyleIndex() + 1];
    case DST:
        return names[textStyle.zoneNameStyleIndex() + 3];
    }
    return names[textStyle.zoneNameStyleIndex() + 5];
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:39,代碼來源:DateTimeFormatterBuilder.java

示例8: interruptPollerThread

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private void interruptPollerThread() {
    SoftReference<Thread> threadSoftReference = pollerThreadReference.getAndSet(null);
    if (threadSoftReference != null) {
        Thread pollerThread = threadSoftReference.get();
        if (pollerThread != null && pollerThread != Thread.currentThread()) {
            // only interrupt poller thread if it's not current thread
            LOGGER.debug("Interrupting poller thread '{}'", pollerThread.getName());
            pollerThread.interrupt();
        }
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:12,代碼來源:WatchServiceFileWatcherBacking.java

示例9: findClass

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
/**
 * Find an already defined (cached) JavaClass object by name.
 */
@Override
public JavaClass findClass(final String className) {
    final SoftReference<JavaClass> ref = loadedClasses.get(className);
    if (ref == null) {
        return null;
    }
    return ref.get();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:SyntheticRepository.java

示例10: retrieveDisplayNamesImpl

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
private static String[] retrieveDisplayNamesImpl(String id, Locale locale) {
    LocaleServiceProviderPool pool =
        LocaleServiceProviderPool.getPool(TimeZoneNameProvider.class);
    String[] names;
    Map<Locale, String[]> perLocale = null;

    SoftReference<Map<Locale, String[]>> ref = cachedDisplayNames.get(id);
    if (Objects.nonNull(ref)) {
        perLocale = ref.get();
        if (Objects.nonNull(perLocale)) {
            names = perLocale.get(locale);
            if (Objects.nonNull(names)) {
                return names;
            }
        }
    }

    // build names array
    names = new String[7];
    names[0] = id;
    for (int i = 1; i <= 6; i ++) {
        names[i] = pool.getLocalizedObject(TimeZoneNameGetter.INSTANCE, locale,
                i<5 ? (i<3 ? "std" : "dst") : "generic", i%2, id);
    }

    if (Objects.isNull(perLocale)) {
        perLocale = new ConcurrentHashMap<>();
    }
    perLocale.put(locale, names);
    ref = new SoftReference<>(perLocale);
    cachedDisplayNames.put(id, ref);
    return names;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:TimeZoneNameUtility.java

示例11: computeIfAbsent

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public CommentHelper computeIfAbsent(Element key) {
    if (wkMap.containsKey(key)) {
        SoftReference<CommentHelper> value = wkMap.get(key);
        if (value != null) {
            CommentHelper cvalue = value.get();
            if (cvalue != null) {
                return cvalue;
            }
        }
    }
    CommentHelper newValue = new CommentHelper(utils.configuration, key, utils.getTreePath(key),
            utils.getDocCommentTree(key));
    wkMap.put(key, new SoftReference<>(newValue));
    return newValue;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:Utils.java

示例12: decodeSampledBitmapFromFileDescriptor

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
/**
 * get bitmap from filedescriptor
 * @author leibing
 * @createTime 2017/3/2
 * @lastModify 2017/3/2
 * @param fd
 * @param reqWidth
 * @param reqHeight
 * @return
 */
public static Bitmap decodeSampledBitmapFromFileDescriptor(FileDescriptor fd, int reqWidth, int reqHeight) {
	// bitmap soft ref
	SoftReference<Bitmap> bitmapSoftRef;
	// first decode with injustdecodebounds=true to check dimensions
	final BitmapFactory.Options options = new BitmapFactory.Options();
	try {
		options.inJustDecodeBounds = true;
		BitmapFactory.decodeFileDescriptor(fd, null, options);
		// calculate insamplesize
		options.inSampleSize = calculateInSampleSize(options, reqWidth,
				reqHeight);
		// decode bitmap with insamplesize set
		options.inJustDecodeBounds = false;
		// bitmap soft ref
		bitmapSoftRef
				= new SoftReference<Bitmap>(BitmapFactory.decodeFileDescriptor(fd, null, options));
		if (bitmapSoftRef != null && bitmapSoftRef.get() != null)
			return bitmapSoftRef.get();
	}catch (OutOfMemoryError ex){
		// add sample size
		options.inSampleSize = options.inSampleSize * 4;
		options.inJustDecodeBounds = false;
		// bitmap soft ref
		bitmapSoftRef
				= new SoftReference<Bitmap>(BitmapFactory.decodeFileDescriptor(fd, null, options));
		if (bitmapSoftRef != null && bitmapSoftRef.get() != null)
			return bitmapSoftRef.get();
	}
	return null;
}
 
開發者ID:leibing8912,項目名稱:JkImageLoader,代碼行數:41,代碼來源:ImageResizer.java

示例13: get

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public Bitmap get(String id){
    if(!cache.containsKey(id))
        return null;
    SoftReference<Bitmap> ref=cache.get(id);
    return ref.get();
}
 
開發者ID:SkylineLabs,項目名稱:FindX,代碼行數:7,代碼來源:MemoryCache.java

示例14: getExcludedZones

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
/**
 * @return a List of zone IDs for zones that will change their GMT
 * offsets in some future time.
 *
 * @since 1.6
 */
static List<String> getExcludedZones() {
    if (hasNoExcludeList) {
        return null;
    }

    List<String> excludeList = null;

    SoftReference<List<String>> cache = excludedIDs;
    if (cache != null) {
        excludeList = cache.get();
        if (excludeList != null) {
            return excludeList;
        }
    }

    byte[] buf = getZoneInfoOldMappings();
    int index = JAVAZM_LABEL_LENGTH + 1;
    int filesize = buf.length;

    try {
      loop:
        while (index < filesize) {
            byte tag = buf[index++];
            int     len = ((buf[index++] & 0xFF) << 8) + (buf[index++] & 0xFF);

            switch (tag) {
            case TAG_ExcludedZones:
                {
                    int n = (buf[index++] << 8) + (buf[index++] & 0xFF);
                    excludeList = new ArrayList<>();
                    for (int i = 0; i < n; i++) {
                        byte m = buf[index++];
                        String name = new String(buf, index, m, "UTF-8");
                        index += m;
                        excludeList.add(name);
                    }
                }
                break loop;

            default:
                index += len;
                break;
            }
        }
    } catch (Exception e) {
        System.err.println("ZoneInfoOld: corrupted " + JAVAZM_FILE_NAME);
        return null;
    }

    if (excludeList != null) {
        excludedIDs = new SoftReference<>(excludeList);
    } else {
        hasNoExcludeList = true;
    }
    return excludeList;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:63,代碼來源:ZoneInfoFile.java

示例15: cachedMethodHandle

import java.lang.ref.SoftReference; //導入方法依賴的package包/類
public MethodHandle cachedMethodHandle(int which) {
    assert(assertIsBasicType());
    SoftReference<MethodHandle> entry = methodHandles[which];
    return (entry != null) ? entry.get() : null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:6,代碼來源:MethodTypeForm.java


注:本文中的java.lang.ref.SoftReference.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。