-
1. Re: Anti -Pattern for creating Session/ Producer
gaohoward Jul 4, 2011 11:17 PM (in response to into_java)I think the doc says it clearly. Every example in hornetq should follow the rule, although many of them only send/receive one message. I found there is a 'perf' example that sends mulitple messages. You can take a look.
Howard
-
2. Re: Anti -Pattern for creating Session/ Producer
into_java Jul 4, 2011 11:46 PM (in response to gaohoward)Hi Yong,
I checked up the perf example and i see it does send messages twice but there is a anti-pattern used there itself as the code says whenever we are sending message a new factory and producer is created. I would like to know how can we avoid this antipattern of creating new producers everytime
i have a new message in a new thread.
To put it in different manner. Each of my threads generate a object which i need to put in queue. Right now i am creating a new session for each of them(I have a single instance of factory for all of them-- from which i create session). But the book says its an anti-pattern to create a session for each message. How can this be avoided. The problem is if i create one session for all of these threds then each session can cater to max of one thread at a time so all other threads would be blocking.
I hope you understand where i am going.
Thanks
-
3. Re: Anti -Pattern for creating Session/ Producer
clebert.suconic Jul 4, 2011 11:54 PM (in response to into_java)You just need to cache the object accordingly. How you do it, it will really depend on what you are doing.
If you have a single thread living, keep it there.
-
4. Re: Anti -Pattern for creating Session/ Producer
into_java Jul 5, 2011 3:27 PM (in response to clebert.suconic)I will try and cache the session object. My only concern is the same session object will now be used across multiple threads to send data. Will try it out and see how the performce is.Thanks
-
5. Re: Anti -Pattern for creating Session/ Producer
clebert.suconic Jul 5, 2011 5:44 PM (in response to into_java)You have to safely reuse it.
Example, a cached instance on a Servlet, but make its usage thread safe.
-
6. Re: Anti -Pattern for creating Session/ Producer
into_java Jul 6, 2011 3:20 AM (in response to clebert.suconic)The performce improved drastically on using the same Session object for multiple producers. I am still using one Anti-pattern of creating multiple producer from single session....but the performance is better than multiple session. I am not sure if i can make the producer thread safe..but it seems ok for now..will update the thread is needed.