-
1. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
ataylor Oct 17, 2013 5:06 AM (in response to khuutantai)creating a session for every message sent or received is an anti pattern, connections and sessions should be long lived. the caveat here is if you are using managed connections in the AS
-
2. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
khuutantai Oct 17, 2013 6:20 AM (in response to ataylor)But i think i should create 1 session per transaction ? i'm using hornetq connection factory in jndi
-
3. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
ataylor Oct 17, 2013 7:01 AM (in response to khuutantai)But i think i should create 1 session per transaction ?
why, it makes no difference
i'm using hornetq connection factory in jndi
which one, is it a amanaged connection factory, if not it wont be associated with any tx and wont be pooled.
-
4. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
khuutantai Oct 17, 2013 8:43 AM (in response to ataylor)Hi,
I got what you mean , i will reuse the session and consumer , but when sending message , the application is running multi-threaded , i have read some where that sessions and consumers is not thread safe ?
I don't think it a managed connection factory , i create and bound the connection factory in
hornetq-jms.xml using the configuration as described on hornetq "Using JMS" manual , everytime i receive an message , i enlist the session to the transaction returned by the TransactionManager .
Thanks for your help Andy .
-
5. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
ataylor Oct 17, 2013 9:05 AM (in response to khuutantai)1 of 1 people found this helpfulI got what you mean , i will reuse the session and consumer , but when sending message , the application is running multi-threaded , i have read some where that sessions and consumers is not thread safe ?
yes that is correct, you will need to use your own pooling.
I don't think it a managed connection factory , i create and bound the connection factory in
hornetq-jms.xml using the configuration as described on hornetq "Using JMS" manual , everytime i receive an message , i enlist the session to the transaction returned by the TransactionManager .
Is this a standalone HornetQ instance? or AS? and is your client a remote client or a JEE application
-
6. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
khuutantai Oct 17, 2013 9:17 AM (in response to ataylor)Hi,
it's not a standalone HornetQ , it's AS and my client is a JEE application .
Thanks,
-
7. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
ataylor Oct 17, 2013 9:24 AM (in response to khuutantai)a couple of things.
1. you should be using the managed connection to send messages, i.e. java:/JmsXA as thats what it is there for.
2. you should not be doing a consumer receive in a JEE component, it blocks server threads which is a bad thing, you should be using an MDB
-
8. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
ataylor Oct 17, 2013 9:24 AM (in response to ataylor)oh and you dont have to enlist anything with a transaction manager, this is done for you when you use an MDB
-
9. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
khuutantai Oct 17, 2013 10:05 AM (in response to ataylor)Hi ,
I will try a few ideas tomorrow . It's an old app , we are trying to upgrade it. And it spawn new thread to receive message .
Thanks so much for your help Andy .
-
10. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
ataylor Oct 17, 2013 10:14 AM (in response to khuutantai)I will try a few ideas tomorrow . It's an old app , we are trying to upgrade it. And it spawn new thread to receive message .
spawning a new thread is even worse, the AS uses the executions thread to associate transaction contexts and classloaders so anything could happen.
Thanks so much for your help Andy .
no worries
-
11. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
khuutantai Oct 17, 2013 10:28 AM (in response to ataylor)Hi ,
i'm sorry, but i really don't understand why spawning new thread is not good , i thought calling new Thread() will spawn a Thread in JVM , is there anything to do with AS threads ?
Thanks
-
12. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
ataylor Oct 17, 2013 10:48 AM (in response to khuutantai)1 of 1 people found this helpfulall threading should be controlled by the AS, it has a limited number of threads that it will reuse for different things, for instance it will associate the current transaction or security context with this thread if there is one, and the classloader may be different between different runs of the thread, spawning a new Thread altho may work for what you want is circumventing this. Part of the reason for using an application server is so you dont have to worry about this, for instance, consuming a message in your MDB, the AS will do all the security, transaction coordination for you as well as take care of thread pools. It will also make sure the classloader used by the thread is the one for your application with only your classes available on it.
-
13. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
khuutantai Oct 17, 2013 11:54 AM (in response to ataylor)Wow, great explanation and it really helpful , i do know about the classloader problem , this application was written when JBoss AS was still using JBossMQ .
Thanks you Andy
-
14. Re: ClientSessionFactoryImpl sessions set build up to thousands of instances
khuutantai Oct 18, 2013 4:06 AM (in response to khuutantai)Hi Andy ,
I checked HornetQ source and it's seem like calling session.close() should remove all reference to that session , it's really weird why they can build up to that size . But i will reuse the session , there is 2 part in this application , the part that do reuse the session and consumer look fine , but the part that create session and consumer eveytime it receive or send message is causing problem . It's really an anti-pattern.
Thanks,