title: Thread safe singleton
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2912281/thread-safety-in-singleton">Thread safety in Singleton</a>  </p>
  </blockquote>
  
  
  
  <p>hi,</p>
  
  <p>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. </p>
  
  <p>I am using the following code to access the dictionary and get the wordset for each document.</p>
  
  <pre><code>IndexWordSet set = Dictionary.getInstance().lookupAllIndexWords(newWord);
  </code></pre>
  
  <p>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.</p>
  
  <p>Is this because the <code>Dictionary.getInstance()</code> 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) </p>