本文整理汇总了Java中java.lang.ref.SoftReference类的典型用法代码示例。如果您正苦于以下问题:Java SoftReference类的具体用法?Java SoftReference怎么用?Java SoftReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SoftReference类属于java.lang.ref包,在下文中一共展示了SoftReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSystemZIDs
import java.lang.ref.SoftReference; //导入依赖的package包/类
/**
* Returns an immutable set of system time zone IDs.
* Etc/Unknown is excluded.
* @return An immutable set of system time zone IDs.
*/
private static synchronized Set<String> getSystemZIDs() {
Set<String> systemZones = null;
if (REF_SYSTEM_ZONES != null) {
systemZones = REF_SYSTEM_ZONES.get();
}
if (systemZones == null) {
Set<String> systemIDs = new TreeSet<String>();
String[] allIDs = getZoneIDs();
for (String id : allIDs) {
// exclude Etc/Unknown
if (id.equals(TimeZone.UNKNOWN_ZONE_ID)) {
continue;
}
systemIDs.add(id);
}
systemZones = Collections.unmodifiableSet(systemIDs);
REF_SYSTEM_ZONES = new SoftReference<Set<String>>(systemZones);
}
return systemZones;
}
示例2: TlSbTlNbwFCImmerseMode
import java.lang.ref.SoftReference; //导入依赖的package包/类
public TlSbTlNbwFCImmerseMode(@NonNull Activity activity) {
mActivityRef = new SoftReference<>(activity);
Window window = activity.getWindow();
WindowUtils.addWindowFlags(window, FLAG_TRANSLUCENT_STATUS);
WindowUtils.addWindowFlags(window, FLAG_TRANSLUCENT_NAVIGATION);
mActivityConfig = new ActivityConfig(activity);
mCompatStatusBarView = setupStatusBarView(activity);
mCompatNavigationBarView = setupNavigationBarView(activity);
mCompatStatusBarView.setBackgroundColor(Color.TRANSPARENT);
if (mCompatNavigationBarView != null) {
mCompatNavigationBarView.setBackgroundColor(Color.TRANSPARENT);
}
}
示例3: sourceDebugExtensionInfo
import java.lang.ref.SoftReference; //导入依赖的package包/类
private SDE sourceDebugExtensionInfo() {
if (!vm.canGetSourceDebugExtension()) {
return NO_SDE_INFO_MARK;
}
SDE sde = (sdeRef == null) ? null : sdeRef.get();
if (sde == null) {
String extension = null;
try {
extension = JDWP.ReferenceType.SourceDebugExtension.
process(vm, this).extension;
} catch (JDWPException exc) {
if (exc.errorCode() != JDWP.Error.ABSENT_INFORMATION) {
sdeRef = new SoftReference<SDE>(NO_SDE_INFO_MARK);
throw exc.toJDIException();
}
}
if (extension == null) {
sde = NO_SDE_INFO_MARK;
} else {
sde = new SDE(extension);
}
sdeRef = new SoftReference<SDE>(sde);
}
return sde;
}
示例4: checkHistory
import java.lang.ref.SoftReference; //导入依赖的package包/类
/**
* Check the history for a map that already has the given property added.
*
* @param property {@link Property} to add.
*
* @return Existing map or {@code null} if not found.
*/
private PropertyMap checkHistory(final Property property) {
if (history != null) {
final SoftReference<PropertyMap> ref = history.get(property);
final PropertyMap historicMap = ref == null ? null : ref.get();
if (historicMap != null) {
if (Context.DEBUG) {
historyHit++;
}
return historicMap;
}
}
return null;
}
示例5: getCachedAliasTable
import java.lang.ref.SoftReference; //导入依赖的package包/类
static Map<String, String> getCachedAliasTable() {
Map<String, String> aliases = null;
SoftReference<Map<String, String>> cache = aliasTable;
if (cache != null) {
aliases = cache.get();
}
return aliases;
}
示例6: getFinalizerObjects
import java.lang.ref.SoftReference; //导入依赖的package包/类
public synchronized Enumeration<?> getFinalizerObjects() {
Vector<?> obj;
if (finalizablesCache != null &&
(obj = finalizablesCache.get()) != null) {
return obj.elements();
}
JavaClass clazz = findClass("java.lang.ref.Finalizer");
JavaObject queue = (JavaObject) clazz.getStaticField("queue");
JavaThing tmp = queue.getField("head");
Vector<JavaHeapObject> finalizables = new Vector<JavaHeapObject>();
if (tmp != getNullThing()) {
JavaObject head = (JavaObject) tmp;
while (true) {
JavaHeapObject referent = (JavaHeapObject) head.getField("referent");
JavaThing next = head.getField("next");
if (next == getNullThing() || next.equals(head)) {
break;
}
head = (JavaObject) next;
finalizables.add(referent);
}
}
finalizablesCache = new SoftReference<Vector<?>>(finalizables);
return finalizables.elements();
}
示例7: getStandardLibraries
import java.lang.ref.SoftReference; //导入依赖的package包/类
/**
* This implementation simply reads and parses `java.class.path' property and creates a ClassPath
* out of it.
* @return ClassPath that represents contents of system property java.class.path.
*/
@Override
public ClassPath getStandardLibraries() {
synchronized (this) {
ClassPath cp = (standardLibs == null ? null : standardLibs.get());
if (cp != null)
return cp;
final String pathSpec = getSystemProperties().get(SYSPROP_JAVA_CLASS_PATH);
if (pathSpec == null) {
cp = ClassPathSupport.createClassPath(new URL[0]);
}
else {
cp = Util.createClassPath (pathSpec);
}
standardLibs = new SoftReference<>(cp);
return cp;
}
}
示例8: getAntInstance
import java.lang.ref.SoftReference; //导入依赖的package包/类
private synchronized static AntInstance getAntInstance() {
AntInstance ai;
if (antInstance != null) {
ai = antInstance.get();
} else {
ai = null;
}
if (ai == null) {
ai = createAntInstance();
// XXX would be more accurate to stuff this struct into by BridgeImpl
// so that it all lives or dies iff that class loader is still alive
// (current impl is just workaround for JDK #6389107)
antInstance = new SoftReference<AntInstance>(ai);
}
return ai;
}
示例9: 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;
}
示例10: getIconForDefault
import java.lang.ref.SoftReference; //导入依赖的package包/类
private static synchronized Image getIconForDefault(Class klass) {
Map<String,Object> icons;
if ((imageCache == null) || ((icons = imageCache.get()) == null)) {
icons = createImageCache();
imageCache = new SoftReference<Map<String,Object>>(icons);
}
String name = klass.getName();
Object img = icons.get(name);
if (img == null) {
return null;
}
if (img instanceof Image) {
return (Image) img;
} else {
Image image = java.awt.Toolkit.getDefaultToolkit().createImage(
BeanSupport.class.getResource((String)img));
icons.put(name, image);
return image;
}
}
示例11: CacheBlock
import java.lang.ref.SoftReference; //导入依赖的package包/类
private CacheBlock(CharSequence code, TokenSequence<HTMLTokenId> tokenSequence, int firstElementIndex, int firstTokenIndex) {
this.code = code;
this.tokenSequence = tokenSequence;
this.startIndex = firstElementIndex;
this.firstTokenIndex = firstTokenIndex;
CacheBlockContent block = new CacheBlockContent(code, tokenSequence, firstTokenIndex);
int blockSize = block.getElements().size();
this.endIndex = firstElementIndex + blockSize;
this.startOffset = blockSize == 0 ? -1 : block.getFirstElement().from();
this.endOffset = blockSize == 0 ? -1 : block.getLastElement().to();
this.lastTokenIndex = block.getLastTokenIndex();
blockReads++;
blockReference = new SoftReference<>(block);
}
示例12: 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;
}
示例13: checkAcceptPermission
import java.lang.ref.SoftReference; //导入依赖的package包/类
/**
* Verify that the given AccessControlContext has permission to
* accept this connection.
*/
void checkAcceptPermission(SecurityManager sm,
AccessControlContext acc)
{
/*
* Note: no need to synchronize on cache-related fields, since this
* method only gets called from the ConnectionHandler's thread.
*/
if (sm != cacheSecurityManager) {
okContext = null;
authCache = new WeakHashMap<AccessControlContext,
Reference<AccessControlContext>>();
cacheSecurityManager = sm;
}
if (acc.equals(okContext) || authCache.containsKey(acc)) {
return;
}
InetAddress addr = socket.getInetAddress();
String host = (addr != null) ? addr.getHostAddress() : "*";
sm.checkAccept(host, socket.getPort());
authCache.put(acc, new SoftReference<AccessControlContext>(acc));
okContext = acc;
}
示例14: getLevelOrderedDevices
import java.lang.ref.SoftReference; //导入依赖的package包/类
/**
* Get the scannables, ordered by level, lowest first
* @param position
* @return
* @throws ScanningException
*/
protected Map<Integer, List<L>> getLevelOrderedDevices() throws ScanningException {
if (sortedObjects!=null && sortedObjects.get()!=null) return sortedObjects.get();
final Collection<L> devices = getDevices();
if (devices == null) return Collections.emptyMap();
final Map<Integer, List<L>> devicesByLevel = new TreeMap<>();
for (L object : devices) {
final int level = object.getLevel();
if (!devicesByLevel.containsKey(level)) devicesByLevel.put(level, new ArrayList<L>(7));
devicesByLevel.get(level).add(object);
}
if (isLevelCachingAllowed()) sortedObjects = new SoftReference<Map>(devicesByLevel);
return devicesByLevel;
}
示例15: instance
import java.lang.ref.SoftReference; //导入依赖的package包/类
/**
* Accessor to get thread-local recycler instance
*/
public static BufferRecycler instance()
{
SoftReference<BufferRecycler> ref = recyclerRef.get();
BufferRecycler bufferRecycler;
if (ref == null) {
bufferRecycler = null;
}
else {
bufferRecycler = ref.get();
}
if (bufferRecycler == null) {
bufferRecycler = new BufferRecycler();
recyclerRef.set(new SoftReference<BufferRecycler>(bufferRecycler));
}
return bufferRecycler;
}