Search in sources :

Example 26 with SoftReference

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;
}
Also used : SoftReference(java.lang.ref.SoftReference)

Example 27 with SoftReference

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;
}
Also used : SoftReference(java.lang.ref.SoftReference) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 28 with SoftReference

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();
}
Also used : LocaleProviderAdapter(sun.util.locale.provider.LocaleProviderAdapter) SoftReference(java.lang.ref.SoftReference) CollatorProvider(java.text.spi.CollatorProvider)

Example 29 with SoftReference

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;
}
Also used : Bitmap(android.graphics.Bitmap) SoftReference(java.lang.ref.SoftReference)

Example 30 with SoftReference

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() };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) FilterColumnTable(org.knime.base.data.filter.column.FilterColumnTable) BitSet(java.util.BitSet) DataRow(org.knime.core.data.DataRow) LinkedHashMap(java.util.LinkedHashMap) DataColumnSpec(org.knime.core.data.DataColumnSpec) SoftReference(java.lang.ref.SoftReference) BufferedDataTable(org.knime.core.node.BufferedDataTable) JoinedRow(org.knime.core.data.def.JoinedRow)

Aggregations

SoftReference (java.lang.ref.SoftReference)56 ReferenceQueue (java.lang.ref.ReferenceQueue)7 Reference (java.lang.ref.Reference)6 WeakReference (java.lang.ref.WeakReference)6 PhantomReference (java.lang.ref.PhantomReference)5 Random (java.util.Random)5 IOException (java.io.IOException)4 Bitmap (android.graphics.Bitmap)3 Context (android.content.Context)2 BitmapFactory (android.graphics.BitmapFactory)2 Handler (android.os.Handler)2 Message (android.os.Message)2 MetaClass (groovy.lang.MetaClass)2 Shape (java.awt.Shape)2 File (java.io.File)2 InputStream (java.io.InputStream)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 PrivilegedAction (java.security.PrivilegedAction)2 PrivilegedActionException (java.security.PrivilegedActionException)2 SecureClassLoader (java.security.SecureClassLoader)2