3 Replies Latest reply on Jan 6, 2011 12:24 AM by Clebert Suconic

    Finalize method on ServerLocator versus HornetQConnectionFactory

    Clebert Suconic Master

      We have made an assumption (including myself) that we could relay on the order of the finalize() calls between HornetQConnectionFactory and ServerLocator.


      On which case this would never cause the warn when the Locator is used by HornetQConnectionFactory.



      However, accordingly to the Java specification: http://java.sun.com/docs/books/jls/second_edition/html/execution.doc.html#44837



      There is no guarantee of such calls. So I will change the ServerLocator to not throw a warn when used inside the ConnectionFactory.

        • 1. Re: Finalize method on ServerLocator versus HornetQConnectionFactory
          Clebert Suconic Master

          BTW: I"m talking about these warns:


          WARNING: The ServerLocator you didn't close was created here:


          at org.hornetq.core.client.impl.ServerLocatorImpl.<init>(ServerLocatorImpl.java:308)

          at org.hornetq.core.client.impl.ServerLocatorImpl.<init>(ServerLocatorImpl.java:396)

          at org.hornetq.api.core.client.HornetQClient.createServerLocatorWithoutHA(HornetQClient.java:110)

          at org.hornetq.jms.client.HornetQConnectionFactory.<init>(HornetQConnectionFactory.java:100)

          at org.hornetq.jms.client.HornetQJMSConnectionFactory.<init>(HornetQJMSConnectionFactory.java:67)

          at org.hornetq.api.jms.HornetQJMSClient.createConnectionFactoryWithoutHA(HornetQJMSClient.java:172)

          at org.hornetq.tests.integration.jms.connection.CloseConnectionFactoryOnGCest.testCloseCFOnGC(CloseConnectionFactoryOnGCest.java:54)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

          at java.lang.reflect.Method.invoke(Method.java:597)

          • 2. Re: Finalize method on ServerLocator versus HornetQConnectionFactory
            Tim Fox Master

            ServerLocators should always be explicitly closed. So the warning makes sense to me. In this case the user did not explicitly close the serverlocator by the time the connection factory was gc'd.


            Not sure why you think this is a problem.

            • 3. Re: Finalize method on ServerLocator versus HornetQConnectionFactory
              Clebert Suconic Master

              There's a ServerLocator at the ConnectionFactory that's only closed on finalize. (as you know (obviously) there's no .close at the ConnectionFactory JMS API)


              The JVM doesn't make any guarantee on ordering of calls between the ConnectionFactory and the ServerLocator itself, leading to several of those messages when you're using the JMS API. I have added a flag to not throw the exception on the ServerLocator aggregated on the ConnectionFactory.