Java's built-in evaluation strategy [1] is 100% pass-by-value [2]. A question regarding that fact arose for me when I read this note in the ActiveMQ documentation: "One thing to note with the VM transport is that messages are passed by reference" [3]. That contradicts the well-known fact about Java.
Another question arose about this: "disable the automatic serialization of ObjectMessage payloads so that the objects are passed by value in 4.x by setting the objectMessageSerializationDefered flag to true" [4]. The documentation leads you to expect that setting objectMessageSerializationDefered to false somehow transforms Java's built-in pass-by-value evaluation strategy to instead do pass-by-reference. ActiveMQ's documentation is incomplete and not 100% crystal clear. Since Java being pass-by-value is a given, the ActiveMQ documentation would be more complete and less confusing if its contradictory use of pass-by-reference and pass-by-value were explained in more detail. To try to understand what context ActiveMQ uses pass-by-reference/pass-by-value, I've looked at some unit tests here [5] and here [6]. Neither of those unit tests exercise what's claimed in the documentation I quoted. I didn't see anything that looked like pass-by-reference in the VMTransport code either [7]. So I did some experimenting. I instantiated a new ActiveMQObjectMessage in a method that implements one of several consumers in the receiving end of a VM transport. In that one mutating consumer's method, I then assigned the locally instantiated new message to the original reference received from the destination that several consumers subscribed to. If ActiveMQ truly does pass-by-reference in the standard sense of the term, then I would expect the assignment of the newly instantiated message created in the one mutating consumer's method would be seen by all the other consumers. I would expect the producer that sent the original message to also be able to observe — after sending the original message — that its original reference would eventually refer to the new message instantiated and assigned in the mutating consumer. Neither of those expectations were borne out in my experiment. Which is not a surprise, since Java doesn't do pass-by-refrence. Therefore my questions are: 1. In what sense does the ActiveMQ documentation mean "passed by reference"? 2. Where can I find existing unit tests that exercise and verify ActiveMQ's expected pass-by-reference/pass-by-value behavior? 3. Is that ActiveMQ documentation even relevant for ActiveMQ 5+? Or only for 3x and 4x? ---- [1] https://bit.ly/WikiPbV [2] https://bit.ly/JavaDudePbV [3] https://bit.ly/VMTransPbR [4] https://bit.ly/DisObjSerPbV [5] https://bit.ly/ObjSerTest [6] https://bit.ly/ObjMsgNotSer [7] https://bit.ly/VMTrans