完整注释,将循环等待时间减少至30S;

This commit is contained in:
magese 2018-08-23 09:41:16 +08:00
parent c026752cbe
commit 74962a171e
1 changed files with 36 additions and 17 deletions

View File

@ -1,42 +1,59 @@
/*
* IK 中文分词 版本 7.0
* IK Analyzer release 7.0
* update by 高志成(magese@live.cn)
* IK 中文分词 版本 7.4
* IK Analyzer release 7.4
* update by Magese(magese@live.cn)
*/
package org.wltea.analyzer.lucene;
import java.io.IOException;
import java.util.Vector;
/**
* 更新扩展词典子线程类
*/
public class UpdateKeeper implements Runnable {
private static final long INTERVAL = 60000L;
private static UpdateKeeper singleton;
private Vector<UpdateJob> filterFactorys;
private static final long INTERVAL = 30000L; // 循环等待时间
private Vector<UpdateJob> filterFactorys; // 更新任务集合
/**
* 私有化构造器阻止外部进行实例化
*/
private UpdateKeeper() {
this.filterFactorys = new Vector<>();
Thread worker = new Thread(this);
worker.setDaemon(true);
worker.start();
}
static UpdateKeeper getInstance() {
if (singleton == null) {
synchronized (UpdateKeeper.class) {
if (singleton == null) {
singleton = new UpdateKeeper();
return singleton;
}
}
}
return singleton;
/**
* 静态内部类实现线程安全单例模式
*/
private static class Builder {
private static UpdateKeeper singleton = new UpdateKeeper();
}
/**
* 获取本类的实例
* 线程安全单例模式
*
* @return 本类的实例
*/
static UpdateKeeper getInstance() {
return UpdateKeeper.Builder.singleton;
}
/**
* 将运行中的IK分词工厂实例注册到本类定时任务中
*
* @param filterFactory 运行中的IK分词器
*/
void register(UpdateJob filterFactory) {
this.filterFactorys.add(filterFactory);
}
/**
* 子线程执行任务
*/
@Override
public void run() {
//noinspection InfiniteLoopStatement
@ -47,7 +64,9 @@ public class UpdateKeeper implements Runnable {
e.printStackTrace();
}
// 如果更新字典任务集合不为空
if (!this.filterFactorys.isEmpty()) {
// 进行循环并执行更新
for (UpdateJob factory : this.filterFactorys) {
try {
factory.update();