[jboss-dev-forums] [Design of JCA on JBoss] - JCA antipattern? Or not?

timfox do-not-reply at jboss.com
Tue Feb 20 17:54:03 EST 2007


Hello all-

I was interested in the JCA opinion on the following:

If I am using a straight JMS connection factory (no JCA) then the following code done in a tight loop is clearly an antipattern:


  | :begin
  | 
  | Connection conn = cf.createConnection();
  | 
  | Session sess = conn.createSession(...);
  | 
  | MessageProducer prod = sess.createProducer();
  | 
  | prod.send(sess.createMessage()));
  | 
  | conn.close();
  | 
  | loop begin
  | 

Since it will be creating a new connection, session etc for every message sent which would be incredibly slow.

However when using JCA the above becomes the "recommended" pattern of usage from within a managed environment (ejb/servlet/mbean) since JCA caches the connection and session so new ones don't actually necessarily get created.

Ok, this is all pretty basic stuff.

But what about the following:


  | :begin
  | 
  | Connection conn = cf.createConnection();
  | 
  | Session sess = conn.createSession(...);
  | 
  | MessageConsumer cons= sess.createConsumer(...);
  | 
  | Message m = cons.receive(1000);
  | 
  | conn.close();
  | 
  | loop begin
  | 
  | 

For straight JMS the above would again be clearly an antipattern.

But what about JCA? It's my understanding that JCA does not cache jms consumers so every call to createConsumer() in the above is going to result in a new consumer being created on the jms provider. I.e. a heavyweight operation.

Would you consider the above to be an antipattern when using JCA? (I.e. using a managed cf)

If users want to receive a JMS message in the context of a distributed transaction using JCA1.5, then what is the recommended way of doing this?



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4019580#4019580

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4019580



More information about the jboss-dev-forums mailing list