title: How to involve a Collection on a spring transaction?
body: <p>I currently have a spring application with hibernate and a PlataformTransactionManager running on Jboss/wildfly.</p>
  
  <p>Some of the methods that manipulate the database also call a bean which contains a LinkedBlockingQueue. This queue stores logging messages that are periodically dispatched to someplace else on another thread (using simple spring @Scheduler).</p>
  
  <p>Would it be possible to make my queue (inside a bean) transactional? ie. if the transaction rollback would I be able to "undo" any operations made on my Collection? What's the best strategy to implement this ?</p>
  
  <p>So, in short something like:</p>
  
  <pre><code>@Service
  @Transactional
  public PersonService {
  
      @Autowired
      EntityManager EM;
  
      @Autowired
      LoggingBuffer logger;
  
      public void addPerson(String name) {
            EM.persist(new Person(.....));
  
            logger.add("New person!");
  
            // A rollback here via some thrown exception would not affect the queue
      }
  }
  
  @Component
  public class LoggingBuffer {
  
       private Queue&lt;String&gt; q= new LinkedBlockingQueue&lt;String&gt;();
  
       public add(String msg){
          q.add(msg);
       }
  }
  </code></pre>