fix reload dict error , optimize code and add some useful log

This commit is contained in:
rockybean 2015-01-22 16:35:50 +08:00
parent b97a6d89d8
commit bb27162a24
2 changed files with 15 additions and 11 deletions

View File

@ -77,7 +77,7 @@ public class Dictionary {
* 配置对象
*/
private Configuration configuration;
private ESLogger logger=null;
public static ESLogger logger=Loggers.getLogger("ik-analyzer");
private static ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
@ -89,8 +89,7 @@ public class Dictionary {
public static final String PATH_DIC_STOP = "ik/stopword.dic";
private Dictionary(){
logger = Loggers.getLogger("ik-analyzer");
}
/**
@ -367,11 +366,11 @@ public class Dictionary {
}
response.close();
} catch (ClientProtocolException e) {
e.printStackTrace();
logger.error( "getRemoteWords {} error" , e , location);
} catch (IllegalStateException e) {
e.printStackTrace();
logger.error( "getRemoteWords {} error" , e , location );
} catch (IOException e) {
e.printStackTrace();
logger.error( "getRemoteWords {} error" , e , location );
}
return buffer;
}
@ -640,6 +639,7 @@ public class Dictionary {
logger.info("重新加载词典...");
// 新开一个实例加载词典减少加载过程对当前词典使用的影响
Dictionary tmpDict = new Dictionary();
tmpDict.configuration = getSingleton().configuration;
tmpDict.loadMainDict();
tmpDict.loadStopWordDict();
_MainDict = tmpDict._MainDict;

View File

@ -9,7 +9,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
public class Monitor implements Runnable {
private static CloseableHttpClient httpclient = HttpClients.createDefault();
/*
* 上次更改时间
@ -40,7 +40,7 @@ public class Monitor implements Runnable {
*/
public void run() {
//超时设置
RequestConfig rc = RequestConfig.custom().setConnectionRequestTimeout(10*1000)
.setConnectTimeout(10*1000).setSocketTimeout(15*1000).build();
@ -72,13 +72,17 @@ public class Monitor implements Runnable {
last_modified = response.getLastHeader("Last-Modified")==null?null:response.getLastHeader("Last-Modified").getValue();
eTags = response.getLastHeader("ETags")==null?null:response.getLastHeader("ETags").getValue();
}
}else{
Dictionary.logger.info("remote_ext_dict {} return bad code {}" , location , response.getStatusLine().getStatusCode() );
}
} catch (Exception e) {
e.printStackTrace();
Dictionary.logger.error("remote_ext_dict {} error!",e , location);
}finally{
try {
response.close();
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}