Class SharingStemmer

java.lang.Object
opennlp.tools.stemmer.SharingStemmer
All Implemented Interfaces:
opennlp.tools.stemmer.Stemmer

@ThreadSafe public final class SharingStemmer extends Object
A Stemmer that is safe to share across threads by routing each call to a per-thread delegate minted from a StemmerFactory. Use it to share a stemmer whose implementation is not itself thread-safe, such as PorterStemmer; thread-safe implementations like SnowballStemmer do not need this wrapper.

The first thread uses a single owner delegate without touching ThreadLocal until a second thread appears, matching the OwnerOrPerThreadState pattern used by the thread-safe *ME components.

  • Constructor Details

    • SharingStemmer

      public SharingStemmer(opennlp.tools.stemmer.StemmerFactory factory)
      Parameters:
      factory - The factory that mints per-thread delegates. Must not be null.
      Throws:
      IllegalArgumentException - if factory is null.
  • Method Details

    • stem

      public CharSequence stem(CharSequence word)
    • stemAll

      public List<CharSequence> stemAll(CharSequence word)
    • clearThreadLocalState

      public void clearThreadLocalState()
      Removes this thread's payload to prevent classloader leaks in container environments. Call when the thread is returned to a pool or the stemmer is no longer needed, mirroring clearThreadLocalState() on the thread-safe *ME components.