- replacing the inefficient Number constructor with static valueOf instead
- remove double-checked locking
This commit is contained in:
parent
71b5211781
commit
81ea266414
@ -115,7 +115,7 @@ class DictSegment implements Comparable<DictSegment>{
|
|||||||
//设置hit的当前处理位置
|
//设置hit的当前处理位置
|
||||||
searchHit.setEnd(begin);
|
searchHit.setEnd(begin);
|
||||||
|
|
||||||
Character keyChar = new Character(charArray[begin]);
|
Character keyChar = Character.valueOf(charArray[begin]);
|
||||||
DictSegment ds = null;
|
DictSegment ds = null;
|
||||||
|
|
||||||
//引用实例变量为本地变量,避免查询时遇到更新的同步问题
|
//引用实例变量为本地变量,避免查询时遇到更新的同步问题
|
||||||
@ -187,7 +187,7 @@ class DictSegment implements Comparable<DictSegment>{
|
|||||||
*/
|
*/
|
||||||
private synchronized void fillSegment(char[] charArray , int begin , int length , int enabled){
|
private synchronized void fillSegment(char[] charArray , int begin , int length , int enabled){
|
||||||
//获取字典表中的汉字对象
|
//获取字典表中的汉字对象
|
||||||
Character beginChar = new Character(charArray[begin]);
|
Character beginChar = Character.valueOf(charArray[begin]);
|
||||||
Character keyChar = charMap.get(beginChar);
|
Character keyChar = charMap.get(beginChar);
|
||||||
//字典中没有该字,则将其添加入字典
|
//字典中没有该字,则将其添加入字典
|
||||||
if(keyChar == null){
|
if(keyChar == null){
|
||||||
@ -280,11 +280,9 @@ class DictSegment implements Comparable<DictSegment>{
|
|||||||
* 线程同步方法
|
* 线程同步方法
|
||||||
*/
|
*/
|
||||||
private DictSegment[] getChildrenArray(){
|
private DictSegment[] getChildrenArray(){
|
||||||
if(this.childrenArray == null){
|
synchronized(this){
|
||||||
synchronized(this){
|
if(this.childrenArray == null){
|
||||||
if(this.childrenArray == null){
|
|
||||||
this.childrenArray = new DictSegment[ARRAY_LENGTH_LIMIT];
|
this.childrenArray = new DictSegment[ARRAY_LENGTH_LIMIT];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.childrenArray;
|
return this.childrenArray;
|
||||||
@ -295,11 +293,9 @@ class DictSegment implements Comparable<DictSegment>{
|
|||||||
* 线程同步方法
|
* 线程同步方法
|
||||||
*/
|
*/
|
||||||
private Map<Character , DictSegment> getChildrenMap(){
|
private Map<Character , DictSegment> getChildrenMap(){
|
||||||
if(this.childrenMap == null){
|
synchronized(this){
|
||||||
synchronized(this){
|
if(this.childrenMap == null){
|
||||||
if(this.childrenMap == null){
|
this.childrenMap = new ConcurrentHashMap<Character, DictSegment>(ARRAY_LENGTH_LIMIT * 2,0.8f);
|
||||||
this.childrenMap = new ConcurrentHashMap<Character, DictSegment>(ARRAY_LENGTH_LIMIT * 2,0.8f);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.childrenMap;
|
return this.childrenMap;
|
||||||
|
@ -103,29 +103,28 @@ public class Dictionary {
|
|||||||
* @return Dictionary
|
* @return Dictionary
|
||||||
*/
|
*/
|
||||||
public static synchronized Dictionary initial(Configuration cfg){
|
public static synchronized Dictionary initial(Configuration cfg){
|
||||||
if(singleton == null){
|
|
||||||
synchronized(Dictionary.class){
|
synchronized(Dictionary.class){
|
||||||
if(singleton == null){
|
if(singleton == null){
|
||||||
singleton = new Dictionary();
|
singleton = new Dictionary();
|
||||||
singleton.configuration=cfg;
|
singleton.configuration=cfg;
|
||||||
singleton.loadMainDict();
|
singleton.loadMainDict();
|
||||||
singleton.loadSurnameDict();
|
singleton.loadSurnameDict();
|
||||||
singleton.loadQuantifierDict();
|
singleton.loadQuantifierDict();
|
||||||
singleton.loadSuffixDict();
|
singleton.loadSuffixDict();
|
||||||
singleton.loadPrepDict();
|
singleton.loadPrepDict();
|
||||||
singleton.loadStopWordDict();
|
singleton.loadStopWordDict();
|
||||||
|
|
||||||
//建立监控线程
|
//建立监控线程
|
||||||
for(String location:cfg.getRemoteExtDictionarys()){
|
for(String location:cfg.getRemoteExtDictionarys()){
|
||||||
//10 秒是初始延迟可以修改的 60是间隔时间 单位秒
|
//10 秒是初始延迟可以修改的 60是间隔时间 单位秒
|
||||||
pool.scheduleAtFixedRate(new Monitor(location), 10, 60, TimeUnit.SECONDS);
|
pool.scheduleAtFixedRate(new Monitor(location), 10, 60, TimeUnit.SECONDS);
|
||||||
}
|
|
||||||
for(String location:cfg.getRemoteExtStopWordDictionarys()){
|
|
||||||
pool.scheduleAtFixedRate(new Monitor(location), 10, 60, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
return singleton;
|
|
||||||
}
|
}
|
||||||
|
for(String location:cfg.getRemoteExtStopWordDictionarys()){
|
||||||
|
pool.scheduleAtFixedRate(new Monitor(location), 10, 60, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return singleton;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return singleton;
|
return singleton;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user