Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6174887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:49:42+00:00 2026-05-23T23:49:42+00:00

I think this is a stupid question, but I can’t quite find the answer

  • 0

I think this is a stupid question, but I can’t quite find the answer I’m looking for in the JMS getting started guide, or indeed elsewhere on the web. This jGuru post suggests that thread safety in the following scenario is up to the application designer.

Scenario

Consider an Object as an attribute of HttpSession. This object is of type ProductQuote.

In a Java Servlet, I take some input from the request and set them to fields in a new instance of ProductQuote and then use another class of mine to push the same ProductQuote instance on to a JMS Queue.

On a separate thread, this object is popped from the queue via the container, and passed to my message driven bean (“MDB”) that implements MessageListener via the onMessage(Message message) method. This particular implementation of the MessageListener interface will mutate a field in the instance and then discard the message, executing cleanly.

Question

Is it possible that the instance of ProductQuote pushed to the queue in the Servlet the exact same instance that is consumed by the MDB in another thread?

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.

Edit
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.

Forgive the stupid question.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:49:44+00:00Added an answer on May 23, 2026 at 11:49 pm

    The answer is defined in the JMS specification and I quote:

    Note that the setObject method of ObjectMessage places a copy of the
    input object in a message

    Given that any JMS provider — in my case BEA Weblogic — would have to adhere to this, I am confident the thread-safety concern in my original message is unfounded: objects that are in ObjectMessage instances are copied and therefore the threat of concurrent modification does not exist.

    Edit

    I should have read the Javadoc too:

    public void setObject(Serializable object)
                   throws JMSException
    

    Sets the serializable object containing this message’s data. It is
    important to note that an ObjectMessage contains a snapshot of the
    object at the time setObject() is called; subsequent modifications of
    the object will have no effect on the ObjectMessage body.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like this is a stupid question, but I can't think of a
I think this can be a stupid question but after read a lot and
It's probably stupid question, but I can not find an answer. How can I
I think this this is a pretty stupid question but I just confused myself
sorry if this question is stupid, but I can't wrap my head around Java
I am new to this and I think question is also too stupid. But
This maybe a stupid question, but as I can not easily undo my change
This may be a really stupid question, but I cannot find anything anywhere as
My question is almost stupid because I think I know the answer but I
I think this could be a very easy question for you. But I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.