added synchonization to the open method

Former-commit-id: 8be1fcc1b96744dbf4d4f5754f2402be33ed4032
This commit is contained in:
Jeremy Long
2014-12-28 06:43:45 -05:00
parent 2c7ab297d7
commit 943a9ea97e

View File

@@ -62,7 +62,7 @@ public final class CpeMemoryIndex {
/** /**
* singleton instance. * singleton instance.
*/ */
private static CpeMemoryIndex instance = new CpeMemoryIndex(); private static final CpeMemoryIndex INSTANCE = new CpeMemoryIndex();
/** /**
* private constructor for singleton. * private constructor for singleton.
@@ -76,7 +76,7 @@ public final class CpeMemoryIndex {
* @return the instance of the CpeMemoryIndex * @return the instance of the CpeMemoryIndex
*/ */
public static CpeMemoryIndex getInstance() { public static CpeMemoryIndex getInstance() {
return instance; return INSTANCE;
} }
/** /**
* The in memory Lucene index. * The in memory Lucene index.
@@ -114,18 +114,20 @@ public final class CpeMemoryIndex {
* @throws IndexException thrown if there is an error creating the index * @throws IndexException thrown if there is an error creating the index
*/ */
public void open(CveDB cve) throws IndexException { public void open(CveDB cve) throws IndexException {
if (!openState) { synchronized (INSTANCE) {
index = new RAMDirectory(); if (!openState) {
buildIndex(cve); index = new RAMDirectory();
try { buildIndex(cve);
indexReader = DirectoryReader.open(index); try {
} catch (IOException ex) { indexReader = DirectoryReader.open(index);
throw new IndexException(ex); } catch (IOException ex) {
throw new IndexException(ex);
}
indexSearcher = new IndexSearcher(indexReader);
searchingAnalyzer = createSearchingAnalyzer();
queryParser = new QueryParser(LuceneUtils.CURRENT_VERSION, Fields.DOCUMENT_KEY, searchingAnalyzer);
openState = true;
} }
indexSearcher = new IndexSearcher(indexReader);
searchingAnalyzer = createSearchingAnalyzer();
queryParser = new QueryParser(LuceneUtils.CURRENT_VERSION, Fields.DOCUMENT_KEY, searchingAnalyzer);
openState = true;
} }
} }
/** /**