src/main/java/org/nustaq/serialization/FSTConfiguration.java
public void returnObject( Object cached ) {
        try {
            while (!cacheLock.compareAndSet(false, true)) {
                // empty
            }
            List<SoftReference> li = cachedObjects.get(cached.getClass());
            if ( li == null ) {
                li = new ArrayList<SoftReference>();
                cachedObjects.put(cached.getClass(),li);
            }
            if ( li.size() < 5 )
                li.add(new SoftReference(cached));
        } finally {
            cacheLock.set(false);
        }
    }
public void returnObject( Object cached ) {
        try {
            while (!cacheLock.compareAndSet(false, true)) {
                // empty
            }
            List<SoftReference> li = cachedObjects.get(cached.getClass());
            if ( li == null ) {
                li = new ArrayList<SoftReference>();
                cachedObjects.put(cached.getClass(),li);
            }
            if ( li.size() < 5 )
                li.add(new SoftReference(cached));
        } finally {
            cacheLock.set(false);
        }
    }
public void returnObject ( Object cached ) { try { while ( ! cacheLock . compareAndSet ( false , true ) ) { // empty } List < SoftReference > li = cachedObjects . get ( cached . getClass ( ) ) ; if ( li == null ) { li = new ArrayList < SoftReference > ( ) ; cachedObjects . put ( cached . getClass ( ) , li ) ; } if ( li . size ( ) < 5 ) li . add ( new SoftReference ( cached ) ) ; } finally { cacheLock . set ( false ) ; } }
reuse heavy weight objects. If a FSTStream is closed, objects are returned and can be reused by new stream instances.
the objects are held in soft references, so there should be no memory issues. FIXME: point of contention !
@param cached
reuse heavy weight objects . If a FSTStream is closed objects are returned and can be reused by new stream instances . the objects are held in soft references so there should be no memory issues . FIXME : point of contention !