[Design of JCA on JBoss] - JCA antipattern? Or not?
by timfox
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
19 years, 1 month
[Design of JBossCache] - WARN message if tx is not ACTIVE or PREPARING
by bstansberry@jboss.com
CacheImpl.getCurrentTransaction() logs a WARN if it finds a tx associated with the thread that isn't ACTIVE or PREPARING.
Found at least one use case where this isn't valid. If a user does some sort of bulk update operation on entities (e.g. 'delete from Customer customer where customer.credit < :creditScore'), as part of afterCompletion() processing Hibernate removes all instances of the entity class. In this case the tx is Status.COMMITTED, leading to a spurious WARN.
Ways to deal with this:
1) Work around the Hibernate usage. In the integration code, these calls go through one method; here we check for a COMMITTED tx and suspend it before calling into JBC (not sure if you can suspend a committed tx). Ugly.
2) Don't warn if the tx is COMMITTED; getCurrentTransaction() just returns null. If a user wants to invoke on the cache as part of afterCompletion() work, there's nothing inherently wrong with that; it just means the call will not be associated with the tx.
3) Get out of the business of this WARN altogether. If a user wants to invoke on the cache as part of a rollback, let them. (I think this deserves the WARN, but I throw it out for completeness.)
My vote's for #2. Thoughts?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4019576#4019576
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4019576
19 years, 1 month