Defer loading the huge optimaize knowledgepool until you really need it. This cuts min memory footprint by 100MB+.
@@ -38,10 +38,15 @@ import java.util.Locale;
*/
public class SimpleDetector implements Detector {
- static private TextObjectFactory textObjectFactory;
- static private LanguageDetector languageDetector;
+ static private Object initGuard = new Object();
+ static private TextObjectFactory textObjectFactory = null;
+ static private LanguageDetector languageDetector = null;
+
+ static private void initOptimaize (boolean useOptimaize) {
+ if (!useOptimaize) return;
+ synchronized (initGuard) {
+ if ((textObjectFactory != null) && (languageDetector != null)) return;
- static {
// origin: https://github.com/optimaize/language-detector
//load all languages:
List<LanguageProfile> languageProfiles;
@@ -59,15 +64,22 @@ public class SimpleDetector implements Detector {
//create a text object factory
textObjectFactory = CommonTextObjectFactories.forDetectingOnLargeText();
}
+ }
private final boolean enableOptimaize;
+ private SimpleDetector(boolean enableOptimaize) {
+ initOptimaize(enableOptimaize);
+ this.enableOptimaize = enableOptimaize;
+
+ }
+
public SimpleDetector() {
- this.enableOptimaize = true;
+ this(true);
}
public SimpleDetector(SimpleLinguisticsConfig.Detector detector) {
- this.enableOptimaize = detector.enableOptimaize();
+ this(detector.enableOptimaize());
}
@Override
