use of java.lang.ref.SoftReference in project jdk8u_jdk by JetBrains.
the class StandardGlyphVector method getDefaultStrike.
// encapsulate access to cached default glyph strike
private GlyphStrike getDefaultStrike() {
GlyphStrike gs = null;
if (fsref != null) {
gs = (GlyphStrike) fsref.get();
}
if (gs == null) {
gs = GlyphStrike.create(this, dtx, null);
fsref = new SoftReference(gs);
}
return gs;
}
use of java.lang.ref.SoftReference in project jdk8u_jdk by JetBrains.
the class SunLayoutEngine method getEngine.
// !!! don't need this unless we have more than one sun layout engine...
public LayoutEngine getEngine(LayoutEngineKey key) {
ConcurrentHashMap cache = (ConcurrentHashMap) cacheref.get();
if (cache == null) {
cache = new ConcurrentHashMap();
cacheref = new SoftReference(cache);
}
LayoutEngine e = (LayoutEngine) cache.get(key);
if (e == null) {
LayoutEngineKey copy = key.copy();
e = new SunLayoutEngine(copy);
cache.put(copy, e);
}
return e;
}
use of java.lang.ref.SoftReference in project jdk8u_jdk by JetBrains.
the class Collator method getInstance.
/**
* Gets the Collator for the desired locale.
* @param desiredLocale the desired locale.
* @return the Collator for the desired locale.
* @see java.util.Locale
* @see java.util.ResourceBundle
*/
public static Collator getInstance(Locale desiredLocale) {
SoftReference<Collator> ref = cache.get(desiredLocale);
Collator result = (ref != null) ? ref.get() : null;
if (result == null) {
LocaleProviderAdapter adapter;
adapter = LocaleProviderAdapter.getAdapter(CollatorProvider.class, desiredLocale);
CollatorProvider provider = adapter.getCollatorProvider();
result = provider.getInstance(desiredLocale);
if (result == null) {
result = LocaleProviderAdapter.forJRE().getCollatorProvider().getInstance(desiredLocale);
}
while (true) {
if (ref != null) {
// Remove the empty SoftReference if any
cache.remove(desiredLocale, ref);
}
ref = cache.putIfAbsent(desiredLocale, new SoftReference<>(result));
if (ref == null) {
break;
}
Collator cachedColl = ref.get();
if (cachedColl != null) {
result = cachedColl;
break;
}
}
}
// make the world safe
return (Collator) result.clone();
}
use of java.lang.ref.SoftReference in project AndroidDynamicLoader by mmin18.
the class ImageCache method getBitmapFromReusableSet.
/**
* @param options - BitmapFactory.Options with out* options populated
* @return Bitmap that case be used for inBitmap
*/
protected Bitmap getBitmapFromReusableSet(BitmapFactory.Options options) {
Bitmap bitmap = null;
if (mReusableBitmaps != null && !mReusableBitmaps.isEmpty()) {
final Iterator<SoftReference<Bitmap>> iterator = mReusableBitmaps.iterator();
Bitmap item;
while (iterator.hasNext()) {
item = iterator.next().get();
if (null != item && item.isMutable()) {
// Check to see it the item can be used for inBitmap
if (canUseForInBitmap(item, options)) {
bitmap = item;
// Remove from reusable set so it can't be used again
iterator.remove();
break;
}
} else {
// Remove from the set if the reference has been cleared.
iterator.remove();
}
}
}
return bitmap;
}
use of java.lang.ref.SoftReference in project knime-core by knime.
the class JoinerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
BufferedDataContainer dc = exec.createDataContainer(JoinedTable.createSpec(inData[0].getDataTableSpec(), inData[1].getDataTableSpec(), m_method, m_suffix));
DataTable leftTable = inData[0];
DataTable rightTable = inData[1];
// in the output
if (JoinedTable.METHOD_FILTER.equals(m_method)) {
DataTableSpec leftTableSpec = leftTable.getDataTableSpec();
DataTableSpec rightTableSpec = rightTable.getDataTableSpec();
LinkedHashSet<String> leftHash = new LinkedHashSet<String>();
for (DataColumnSpec c : leftTableSpec) {
leftHash.add(c.getName());
}
LinkedHashSet<String> rightHash = new LinkedHashSet<String>();
for (DataColumnSpec c : rightTableSpec) {
rightHash.add(c.getName());
}
rightHash.removeAll(leftHash);
String[] survivors = rightHash.toArray(new String[rightHash.size()]);
if (survivors.length < rightTableSpec.getNumColumns()) {
rightTable = new FilterColumnTable(rightTable, survivors);
}
}
final BitSet rightRows = new BitSet(inData[1].getRowCount());
final LinkedHashMap<RowKey, SoftReference<Helper>> map = new LinkedHashMap<RowKey, SoftReference<Helper>>(1024);
m_leftRows = 0;
m_outputRows = 0;
m_leftIt = null;
m_rightIt = null;
m_firstMapHelper = null;
m_exec = exec;
if (m_ignoreMissingRows) {
m_max = Math.min(inData[0].getRowCount(), inData[1].getRowCount());
} else {
m_max = Math.max(inData[0].getRowCount(), inData[1].getRowCount());
}
while (true) {
if (!readLeftChunk(leftTable, map)) {
if (!m_ignoreMissingRows) {
processRemainingRightRows(dc, leftTable, rightTable, rightRows);
}
break;
}
if ((m_rightIt == null) || (!m_rightIt.hasNext()) || (rightRows.nextClearBit(0) <= m_rightIt.getIndex())) {
m_rightIt = new CounterRowIterator(rightTable.iterator());
}
while (m_rightIt.hasNext() && (map.size() > 0)) {
m_exec.checkCanceled();
DataRow rightRow = m_rightIt.next();
SoftReference<Helper> sr = map.get(rightRow.getKey());
if (sr != null) {
Helper h = sr.get();
if (h == null) {
map.remove(rightRow.getKey());
} else {
h.m_rightRow = rightRow;
h.m_rightIndex = m_rightIt.getIndex();
if (h.m_leftIndex == m_leftRows) {
// m_firstMapHelper = h;
assert h.m_predecessor == null || !map.containsKey(h.m_predecessor.m_leftRow.getKey());
h.m_predecessor = null;
DataRow joinedRow = new JoinedRow(h.m_leftRow, h.m_rightRow);
dc.addRowToTable(joinedRow);
map.remove(rightRow.getKey());
rightRows.set(m_rightIt.getIndex());
m_leftRows++;
m_outputRows++;
printProgress(rightRow.getKey());
}
}
}
}
processRemainingLeftRowsInMap(dc, rightTable, map, rightRows);
if (!m_ignoreMissingRows) {
if (rightRows.cardinality() == inData[1].getRowCount()) {
processRemainingLeftRowsInTable(dc, leftTable, rightTable);
}
} else {
m_leftRows += map.size();
map.clear();
if (rightRows.cardinality() == inData[1].getRowCount()) {
break;
}
}
}
m_leftIt = null;
m_rightIt = null;
m_exec = null;
m_firstMapHelper = null;
dc.close();
return new BufferedDataTable[] { dc.getTable() };
}
Aggregations