1 2 Previous Next 29 Replies Latest reply on Mar 24, 2010 3:54 PM by leosbitto Go to original post
      • 15. Re: HornetQ - Pooling resources is hard!
        monteirosp
        Nopz, it's a standard Tomcat, not someone embedded with a JEE app server.
        • 16. Re: HornetQ - Pooling resources is hard!
          timfox
          So.. you'll need to either write your own pooling, or use the tomcat in the jboss as distribution
          • 17. Re: HornetQ - Pooling resources is hard!
            monteirosp

            That leads to the beginning of the conversation.

             

            Pure JMS specification objects are hard to pool, because once the server crash or goes offline due to some network problem, the cached sessions, producers and consumers become "broken" and there's no way to check their consistency and purge the bad ones out of the pool.

             

            I saw using the HornetQ client library instead of the JMS, provides better functionalities and more control over object's state (ready or not for duty), providing also connection retries. Is that correct?

             

            Thanks

            • 18. Re: HornetQ - Pooling resources is hard!
              timfox

              MonteiroSP wrote:

               

              That leads to the beginning of the conversation.

               

              Pure JMS specification objects are hard to pool, because once the server crash or goes offline due to some network problem, the cached sessions, producers and consumers become "broken" and there's no way to check their consistency and purge the bad ones out of the pool.

               



              That's not correct, the JCA adaptor, handles dead connections, and it just uses the standard JMS API.

               

              In JMS you can set an ExceptionListener on a connection and it will be called in event of connection failure.


              • 19. Re: HornetQ - Pooling resources is hard!
                leosbitto

                Quoting JMS 1.1 specification, chapter 4.3.5 Closing a Connection: "Once a connection has been closed, an attempt to use it or its sessions or their
                message consumers and producers must throw an IllegalStateException (calls to the close method of these objects must be ignored)."

                 

                HornetQ was not compliant with this part of the JMS spec in some older beta releases, but it does comply in the current GA release. In my framework (no JCA, no JEE container) I shutdown and recreate the application thread which gets such exception, and I recreate the Connection when its ExceptionListener gets called. Threads use the shared Connection when they start to create their Sessions and following JMS objects. It seems to work fine so far.

                 

                Please note that you cannot actually pool JMS Sessions and objects created from them (producers, consumers) between the threads - the JMS spec mandates that they must not be shared between threads! So making each thread create its own JMS Session(s) etc. is a reasonable approach, I think.

                • 20. Re: HornetQ - Pooling resources is hard!
                  timfox

                  LeosBitto wrote:

                   

                  Quoting JMS 1.1 specification, chapter 4.3.5 Closing a Connection: "Once a connection has been closed, an attempt to use it or its sessions or their
                  message consumers and producers must throw an IllegalStateException (calls to the close method of these objects must be ignored)."

                   

                  HornetQ was not compliant with this part of the JMS spec in some older beta releases, but it does comply in the current GA release. In my framework (no JCA, no JEE container) I shutdown and recreate the application thread which gets such exception, and I recreate the Connection when its ExceptionListener gets called. Threads use the shared Connection when they start to create their Sessions and following JMS objects. It seems to work fine so far.

                   

                  Please note that you cannot actually pool JMS Sessions and objects created from them (producers, consumers) between the threads - the JMS spec mandates that they must not be shared between threads! So making each thread create its own JMS Session(s) etc. is a reasonable approach, I think.

                  Well, almost To clarify, a JMS session can be shared between different threads, it just mustn't be accessed by more than one thread *concurrently*.

                   

                  From the spec:

                   

                  "There are no restrictions on the number of threads that can use a Session object or those it creates. The restric-
                  tion is that the resources of a Session should not be used concurrently by multiple threads. It is up to the user
                  to insure that this concurrency restriction is met. The simplest way to do this is to use one thread. In the case
                  of asynchronous delivery, use one thread for setup in stopped mode and then start asynchronous delivery.
                  In more complex cases the user must provide explicit synchronization."

                  • 21. Re: HornetQ - Pooling resources is hard!
                    timfox

                    Although I do think some people pool JMS resources out of habit, and where unnecessary, perhaps due to bad habits caused by e.g. usage of the Spring JMS Template, there are valid reasons for pooling, outside the app server environment, e.g. standalone servlet engine.

                     

                    Perhaps we should consider writing a pool for these use cases?

                     

                    If so, someone could create a JIRA....

                    • 22. Re: HornetQ - Pooling resources is hard!
                      leosbitto
                      Tim you are right. I was too focused on the use case when there is a transactional jms session opened at the beginning of the processing and committed (or rolled back) at the end (and repeated) - in this case it is easiest for each thread to manage its own jms session. However, in different use cases it obviously might be beneficial to share the jms sessions.
                      • 23. Re: HornetQ - Pooling resources is hard!
                        leosbitto
                        Tim, I think that the users would appreciate having an easy and efficient JMS access outside of JEE container. I believe that providing implementations of ConnectionFactory, Connection and Sesion which would do proper caching of the created objects should not be too difficult. I could contribute such code if you would like.
                        • 24. Re: HornetQ - Pooling resources is hard!
                          monteirosp
                          Hey Tim! That would be great to have a smart way on dealing with JMS objects in a standalone app or a simple servlet container. Are you guys opening a JIRA ticket? Want me to do so?
                          • 25. Re: HornetQ - Pooling resources is hard!
                            monteirosp
                            Ops... duplicated post.

                             

                            Message was edited by: Cristiano Monteiro

                            • 26. Re: HornetQ - Pooling resources is hard!
                              clebert.suconic

                              Basically Tim was asking you to open the JIRA. You would put your name on the history of HornetQ :-)

                               

                              https://jira.jboss.org/jira/browse/HORNETQ

                               

                              but If you don't want to.. I can do it myself :-)

                              • 27. Re: HornetQ - Pooling resources is hard!
                                monteirosp

                                For vanity sake, it's opened:

                                https://jira.jboss.org/jira/browse/HORNETQ-329

                                 

                                Please take a look, it's my first JIRA submit

                                • 28. Re: HornetQ - Pooling resources is hard!
                                  timfox

                                  Leos Bitto wrote:

                                   

                                  Tim, I think that the users would appreciate having an easy and efficient JMS access outside of JEE container. I believe that providing implementations of ConnectionFactory, Connection and Sesion which would do proper caching of the created objects should not be too difficult. I could contribute such code if you would like.

                                  Leos, sure take a stab at the JIRA if you like.

                                   

                                  I'd suggest first making a proposal about how you intend to do it on the dev forum.

                                  • 29. Re: HornetQ - Pooling resources is hard!
                                    leosbitto

                                    Tim Fox wrote:

                                     

                                     

                                    Leos, sure take a stab at the JIRA if you like.

                                     

                                    I'd suggest first making a proposal about how you intend to do it on the dev forum.

                                     

                                    My proposal with the initial implementation is on the dev forum.

                                    1 2 Previous Next