title: Can or is the Object held within a JMS ObjectMessage the same instance as when published?
body: <p>I think this is a stupid question, but I can't quite find the answer I'm looking for in the <a href="http://java.sun.com/developer/technicalArticles/Ecommerce/jms/index.html" rel="nofollow">JMS getting started guide</a>, or indeed elsewhere on the web. <a href="http://www.jguru.com/faq/view.jsp?EID=1120" rel="nofollow">This jGuru post</a> suggests that thread safety in the following scenario is up to the application designer.</p>
  
  <h2>Scenario</h2>
  
  <p>Consider an <code>Object</code> as an attribute of <code>HttpSession</code>. This object is of type <code>ProductQuote</code>.</p>
  
  <p>In a Java Servlet, I take some input from the request and set them to fields in a new instance of <code>ProductQuote</code> and then use another class of mine to push the same <code>ProductQuote</code> instance on to a JMS Queue. </p>
  
  <p>On a separate thread, this object is popped from the queue via the container, and passed to my message driven bean ("MDB") that <code>implements MessageListener</code> via the <a href="http://download.oracle.com/javaee/1.3/api/javax/jms/MessageListener.html#onMessage%28javax.jms.Message%29" rel="nofollow"><code>onMessage(Message message)</code></a> method. This particular implementation of the <code>MessageListener</code> interface will mutate a field in the instance and then discard the message, executing cleanly.</p>
  
  <h2>Question</h2>
  
  <p>Is it possible that the instance of <code>ProductQuote</code> pushed to the queue in the Servlet the exact same instance that is consumed by the MDB in another thread?</p>
  
  <p>I am assuming the reverse is also possible (if not always; I'm trying to fill a gap in my knowledge): that an instance pushed to a queue/topic is not the same instance as that passed to consumers.</p>
  
  <p><em>Edit</em>
  For additional clarification, I am pondering thread safety in the given scenario, where an object in the session could be modified at the same time an MDB is modifying/reading it.</p>
  
  <p>Forgive the stupid question.</p>