Update Dictionary.java
-- 修改的 建立监控线程部分代码 改用ScheduledExecutorService, 之前的while(true) sleep不能算是一种优雅的执行周期任务的方式,相应的Monitor类将while部分做了剔除
This commit is contained in:
parent
9da221e218
commit
8a49a5ed88
@ -25,6 +25,20 @@
|
||||
*/
|
||||
package org.wltea.analyzer.dic;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
@ -35,11 +49,6 @@ import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.wltea.analyzer.cfg.Configuration;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 词典管理类,单子模式
|
||||
*/
|
||||
@ -69,13 +78,18 @@ public class Dictionary {
|
||||
*/
|
||||
private Configuration configuration;
|
||||
private ESLogger logger=null;
|
||||
|
||||
private static ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
|
||||
|
||||
public static final String PATH_DIC_MAIN = "ik/main.dic";
|
||||
public static final String PATH_DIC_SURNAME = "ik/surname.dic";
|
||||
public static final String PATH_DIC_QUANTIFIER = "ik/quantifier.dic";
|
||||
public static final String PATH_DIC_SUFFIX = "ik/suffix.dic";
|
||||
public static final String PATH_DIC_PREP = "ik/preposition.dic";
|
||||
public static final String PATH_DIC_STOP = "ik/stopword.dic";
|
||||
|
||||
private Dictionary(){
|
||||
|
||||
logger = Loggers.getLogger("ik-analyzer");
|
||||
}
|
||||
|
||||
@ -102,12 +116,11 @@ public class Dictionary {
|
||||
|
||||
//建立监控线程
|
||||
for(String location:cfg.getRemoteExtDictionarys()){
|
||||
Thread monitor = new Thread(new Monitor(location));
|
||||
monitor.start();
|
||||
//10 秒是初始延迟可以修改的 60是间隔时间 单位秒
|
||||
pool.scheduleAtFixedRate(new Monitor(location), 10, 60, TimeUnit.SECONDS);
|
||||
}
|
||||
for(String location:cfg.getRemoteExtStopWordDictionarys()){
|
||||
Thread monitor = new Thread(new Monitor(location));
|
||||
monitor.start();
|
||||
pool.scheduleAtFixedRate(new Monitor(location), 10, 60, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
return singleton;
|
||||
|
Loading…
x
Reference in New Issue
Block a user