title: JMS Message Driven Bean worker synchronization
body: <p>We are just starting to build our JMS architecture and have the following basic setup:</p>
  
  <ol>
  <li>GLassfish v2.1</li>
  <li>MDB listening on a Topic through a TopicConnectionFactory (all on local server)</li>
  </ol>
  
  <p>Now, the MDB spawns a worker thread when a new message arrives and even though we have in order delivery of messages, we need a synchronization mechanism so that threads check for a certain condition before processing the request concurrently.</p>
  
  <p>Is there a way for these threads to share data? Or are there any other mechanisms (except for database table/row locks) that we can use for synchronization?</p>
  
  <p>Thanks in advance.</p>
  
  <hr>
  
  <p>To clarify, I am not creating my own threads. As everyone rightly pointed out, the container does that for me. Let me help explain my dilemma with an example.</p>
  
  <p>-Message A arrives at t=0 which 'creates' data id 1</p>
  
  <p>-Message B arrives at t=0.1 which 'updates' data id 1</p>
  
  <p>Now assuming the container spawns 2 workers to process A &amp; B and that it takes much more time to 'create' data than update it, the update would process earlier and have no effect.</p>
  
  <p>To be clearer,</p>
  
  <p>-While processing Message B, I would look for data id 1 at t=1 (not find it and thus have finish without doing anything).</p>
  
  <p>-Data id 1 would be created while processing Message A at t=2.</p>