Help with long running transactions

Discussions

EJB programming & troubleshooting: Help with long running transactions

  1. Help with long running transactions (1 messages)

    If there is existing doc/threads that answer this question, please point me. 10 minutes of google and forum searching hasn't turned up what I'm looking for...

    I've been brought in to help a troubled team. The have a few web apps utilizing EJB 2 and running in JBoss 3.2.5. In addition to browser access, they also offer some services like PO imports and Invoice processing, both of which can be done in batches. Everthing they do runs in single, long-running transactions because they just use "Required" everywhere! So, for example, if you are bringing in a batch of PO's (one long-running transaction) and someone logs into the web (a normal length transaction), you'll start getting deadlock errors and/or timeout errors.

    There's some awkward code in here. The developers learned more and more about XDoclet as they went along, but never went back and fixed anything. In a single Session Bean method, it is not uncommon to find them sitting on the Entity Bean and making some calls on it directly, while at the same time working with a "Data Object" from an entity bean AND working with a "Value Object" from an entity bean--yes, all in the same method! It's frightening.

    I know the obvious steps to clean up much of this--however, I have never been faced with long-running transactions (like up to 3 minutes). Can someone describe to me or point me to a good pattern? At the beginning of a PO batch import, there are several company and user records we have to obtain--but locking them for the duration is killing the web users!

    I've thought about sticking a DAO layer between the Session Beans and the Entity Beans, but I still don't know the best use of transactions to get the data we need, do the "crunching," and then update the data. Can this be done effectively with container-managed transactions? Should I modify their session beans to use bean-managed transactions? Because of their piles of kludgy code, transactions are killing me.

    Basically, for these long-running processes, I need a way to: 1) Get the bits of data we need for processing--but without keeping those records locked; 2) Do all the XML work/object creation; 3) Create/update records as necessary, while keeping the record locking to as brief a period as possible.

    A pattern, anyone? Thanks so much!
  2. Hi Charles -
    Ouch! (I feel your pain!) I wish I could steer you in the direction of a pattern, but with the descriptions of your circumstances I'm not sure that would solve your underlying problem. I think that one of the best things you can do is look at the ACID characteristics of the beans themselves and change the deployment descriptor appropriately to reflect the true transaction needs. e.g. If an item is read-only, change its transaction characteristics to NotSupported.

    In the meantime, one book that you might look at for your own reference though (if you don't already have it) is,
    Enterprise Integration Patterns, by Gregor Hohpe and Bobby Woolf (@ Amazon.com http://www.amazon.com/gp/product/0321200683/sr=1-1/qid=1137537429/ref=pd_bbs_1/002-9456733-9215242?%5Fencoding=UTF8)

    It has several patterns that are useful for long running processes and distributed processes.

    Jon