Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dictionary class Multi Thread NullPointerException issue #34

Closed
hujing101 opened this issue May 22, 2014 · 1 comment
Closed

Dictionary class Multi Thread NullPointerException issue #34

hujing101 opened this issue May 22, 2014 · 1 comment

Comments

@hujing101
Copy link

Dictionary类的initial方法在初始化的时候使用的双重检测方法是有问题的,不能保证在多线程环境下Dictionary单例的初始化完成。导致后续使用isStopWord方法时出现了NullPointerException,修改initial方法为在方法级别使用synchronized关键字后问题消失,修改后的代码为:
public static synchronized Dictionary initial(Configuration cfg) {
if (singleton == null) {
singleton = new Dictionary();
singleton.configuration = cfg;
singleton.loadMainDict();
singleton.loadSurnameDict();
singleton.loadQuantifierDict();
singleton.loadSuffixDict();
singleton.loadPrepDict();
singleton.loadStopWordDict();
}
return singleton;
}

@medcl
Copy link
Member

medcl commented Jul 4, 2014

already in master

@medcl medcl closed this as completed Jul 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants