Class MultiThreadedJLanguageTool


  • public class MultiThreadedJLanguageTool
    extends JLanguageTool
    A variant of JLanguageTool that uses several threads for rule matching. Use this if you want text checking to be fast and do not care about the high load that this might cause. Call shutdown() when you don't need the object anymore.

    Also see the javadoc of JLanguageTool.

    Thread-safety: this class is not thread-safe, see the remarks at JLanguageTool.

    • Field Detail

      • threadPoolSize

        private final int threadPoolSize
      • threadPool

        private final java.util.concurrent.ExecutorService threadPool
    • Constructor Detail

      • MultiThreadedJLanguageTool

        public MultiThreadedJLanguageTool​(Language language)
      • MultiThreadedJLanguageTool

        public MultiThreadedJLanguageTool​(Language language,
                                          int threadPoolSize)
        Parameters:
        threadPoolSize - the number of concurrent threads
        Since:
        2.9
        See Also:
        shutdown()
      • MultiThreadedJLanguageTool

        public MultiThreadedJLanguageTool​(Language language,
                                          Language motherTongue)
        See Also:
        shutdown()
      • MultiThreadedJLanguageTool

        public MultiThreadedJLanguageTool​(Language language,
                                          Language motherTongue,
                                          UserConfig userConfig)
        Since:
        4.2
      • MultiThreadedJLanguageTool

        public MultiThreadedJLanguageTool​(Language language,
                                          Language motherTongue,
                                          int threadPoolSize,
                                          UserConfig userConfig)
        Parameters:
        threadPoolSize - the number of concurrent threads
        Since:
        2.9 UserConfig added, 4.2
        See Also:
        shutdown()
    • Method Detail

      • shutdown

        public void shutdown()
        Call this to shut down the internally used thread pool.
        Since:
        3.0
      • shutdownWhenDone

        public void shutdownWhenDone()
        Call this to shut down the internally used thread pool after all running tasks are finished.
        Since:
        3.1
      • getDefaultThreadCount

        private static int getDefaultThreadCount()
      • getThreadPoolSize

        protected int getThreadPoolSize()
        When no thread pool size is configured, the number of available processors is returned.
      • getExecutorService

        protected java.util.concurrent.ExecutorService getExecutorService()
        Returns:
        a fixed size executor with the given number of threads
      • analyzeSentences

        protected java.util.List<AnalyzedSentence> analyzeSentences​(java.util.List<java.lang.String> sentences)
                                                             throws java.io.IOException
        Overrides:
        analyzeSentences in class JLanguageTool
        Throws:
        java.io.IOException