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,6 +114,7 @@ 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 {
synchronized (INSTANCE) {
if (!openState) { if (!openState) {
index = new RAMDirectory(); index = new RAMDirectory();
buildIndex(cve); buildIndex(cve);
@@ -128,6 +129,7 @@ public final class CpeMemoryIndex {
openState = true; openState = true;
} }
} }
}
/** /**
* A flag indicating whether or not the index is open. * A flag indicating whether or not the index is open.
*/ */