Possible Duplicate:
Thread safety in Singleton
hi,
I am using wordnet dictionary to find the synonyms for words. As I have lots documents I have used multiple threads to do the document pre-processing which involves stemming, stop word removal and synonym replacement.
I am using the following code to access the dictionary and get the wordset for each document.
IndexWordSet set = Dictionary.getInstance().lookupAllIndexWords(newWord);
This works fine in a single threaded environment. But in a multi threaded environment this didn't work as expected. The program gets stuck after some time.
Is this because the Dictionary.getInstance()
is a singleton class and it is not thread safe? If so how can I modify the access to the dictionary so that it is thread safe? ( I cannot modify the dictionary class since I have used a dictionary library)