edu.stanford.nlp.util.concurrent.SynchronizedInterner Maven / Gradle / Ivy
Show all versions of stanford-parser Show documentation
package edu.stanford.nlp.util.concurrent;
import java.util.Set;
import edu.stanford.nlp.util.Generics;
import edu.stanford.nlp.util.Interner;
/**
*
* For interning (canonicalizing) things in a multi-threaded environment.
*
*
*
* Maps any object to a unique interned version which .equals the
* presented object. If presented with a new object which has no
* previous interned version, the presented object becomes the
* interned version. You can tell if your object has been chosen as
* the new unique representative by checking whether o == intern(o).
* The interners use a concurrent map with weak references, meaning that
* if the only pointers to an interned item are the interners' backing maps,
* that item can still be garbage collected. Since the gc thread can
* silently remove things from the backing map, there's no public way to
* get the backing map, but feel free to add one at your own risk.
*
* Note that in general it is just as good or better to use the
* static SynchronizedInterner.globalIntern() method rather than making an
* instance of SynchronizedInterner and using the instance-level intern().
*
*
* @author Ilya Sherman
* @see edu.stanford.nlp.util.Interner
*/
// TODO would be nice to have this share an interface with Interner
public class SynchronizedInterner {
protected static final Object globalMutex = new Object();
protected static SynchronizedInterner