If I create 2 different publishers on 2 different topics from the SAME session, can I use the 2 publishers on 2 different threads? Although each publisher is operated by a single thread, they do share the same session and connection. Is this alright?
Likewise, if I create a publisher and a subcriber from the Same session, am I breaking anything?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Okay. After reading posts from other forums, it seems to me that having 2 publishers operating on the same session in 2 threads is bad.
As a result, I will need to have a pool of publishers. Each of them will have its own session. When I need to publish to a topic, I will get a publisher and then pass in the topic. The function signature is:
public void publish(Topictopic, Messagemessage)
However, topics are created via a TopicSession. So, can a topic created by one TopicSession be used by another?
In the pool case, the topics are created by a controler TopicSession. But the topic must be passed to the publisher who is using its own TopicSession. Is this okay?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, I have more questions on multi-thread.
If I create 2 different publishers on 2 different topics from the SAME session, can I use the 2 publishers on 2 different threads? Although each publisher is operated by a single thread, they do share the same session and connection. Is this alright?
Likewise, if I create a publisher and a subcriber from the Same session, am I breaking anything?
Thanks.
Okay. After reading posts from other forums, it seems to me that having 2 publishers operating on the same session in 2 threads is bad.
As a result, I will need to have a pool of publishers. Each of them will have its own session. When I need to publish to a topic, I will get a publisher and then pass in the topic. The function signature is:
public void publish(Topictopic, Messagemessage)
However, topics are created via a TopicSession. So, can a topic created by one TopicSession be used by another?
In the pool case, the topics are created by a controler TopicSession. But the topic must be passed to the publisher who is using its own TopicSession. Is this okay?
Thanks.
Hello there,
Topic objects are totally thread-safe. You can pass them around as you see fit.
The JMS spec defines that connection factories and destinations must be thread-safe objects. Other objects are implementation specific.
-james