title: How to persist Object in ThreadPoolTaskExecutor
body: <p>I need to implement a following architecture:</p>
  
  <p>N threads are monitoring <code>BlockedQueue&lt;Message&gt;</code> (I can even consider that we can use ActiveMQ in near future).</p>
  
  <p>When message captured I perform few modification on this message and I need to persist it in MongoDB database.</p>
  
  <p>The service is something like this:</p>
  
  <pre><code>@Repository(value="service")
  public class Service {
  
      @Autowired
      MongoTemplate mongoTemplate; 
  
  public void save(Message message){
    //do something to message
    doSomething(message);
    //persist it
    mongoTemplate.save(message, "messages");
  }
  //etc...
  }
  </code></pre>
  
  <p>Now I need to share <code>Service</code> object between threads. </p>
  
  <p>How can I make this service Thread-Safe? Will it be good practice to make Service object as singleton (Design Pattern) and inject it to Runnabble beans using <code>getInstance()</code> method factory? </p>
  
  <p>Should my mongoDb template have N connections opened(kind of connection pool)? </p>
  
  <p>May be there are some other ways to share such service between threads?</p>