diff options
author | Harald Musum <musum@verizonmedia.com> | 2019-05-22 10:59:56 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2019-05-22 10:59:56 +0200 |
commit | 5d4740e52fb7374df503df46f3f5c0489be94292 (patch) | |
tree | 03dc74a334c0b65973e760653d28039e89fd517e /container-core | |
parent | 11b0f0b29f816e9208afdc787615b9fe0e8575a1 (diff) |
Do lazy initialization of default linguistics provider
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/language/provider/DefaultLinguisticsProvider.java | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/container-core/src/main/java/com/yahoo/language/provider/DefaultLinguisticsProvider.java b/container-core/src/main/java/com/yahoo/language/provider/DefaultLinguisticsProvider.java index 8f08e33a777..d9af9bf88b2 100644 --- a/container-core/src/main/java/com/yahoo/language/provider/DefaultLinguisticsProvider.java +++ b/container-core/src/main/java/com/yahoo/language/provider/DefaultLinguisticsProvider.java @@ -1,10 +1,12 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.language.provider; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.inject.Inject; -import com.yahoo.language.opennlp.OpenNlpLinguistics; import com.yahoo.container.di.componentgraph.Provider; import com.yahoo.language.Linguistics; +import com.yahoo.language.opennlp.OpenNlpLinguistics; /** * Provides the default linguistics implementation if no linguistics component has been explicitly configured @@ -14,14 +16,15 @@ import com.yahoo.language.Linguistics; */ public class DefaultLinguisticsProvider implements Provider<Linguistics> { - private final Linguistics linguistics; + // Use lazy initialization to avoid expensive (memory-wise) instantiation f + private volatile Supplier<Linguistics> linguisticsSupplier = Suppliers.memoize(OpenNlpLinguistics::new); @SuppressWarnings("deprecation") @Inject - public DefaultLinguisticsProvider() { linguistics = new OpenNlpLinguistics(); } + public DefaultLinguisticsProvider() { } @Override - public Linguistics get() { return linguistics; } + public Linguistics get() { return linguisticsSupplier.get(); } @Override public void deconstruct() {} |