JBoss 5.1 - Chapter 02.2 - Customizing JBoss AS Transaction Service

From Training Material
Jump to navigation Jump to search
Title
Transactions
Author
Bernard Szlachta (NobleProg Ltd)

Transactions Levels ⌘

  • Single Resource (e.g. Database)
  • Multiple resources (e.g. database and a message)
  • Multiple systems (two-phase commit)

Transaction ⌘

ACID property:

  • Atomic (all of none tasks performed)
  • Consistent (after completion, systems and consistent)
  • Isolated (other system cannot see what is in transaction)
  • Durable (once completed, it will persist)

Locking ⌘

  • Pessimistic (lock resources)
  • Optimistic (assumes underlying data will not change)

Global vs Local ⌘

  • Local (single resource, e.g. single database)
  • Global (Two-phase commit)

Container Managed vs User Transaction ⌘

  • User transaction
  • Container Managed transactions

User Transactions ⌘

Programm user decide when to start, commit or roll-back (see Security example)

UserTransaction.begin()

try {
  //do some stuff
  UserTransaction.commit()
} catch {
    UserTransaction.rollback()
}

Container Managed Transactions ⌘

  • Enabled by default
  • System exception - implicit rollback
  • Application exception - needs to be handled manually

Transaction Attribute ⌘

  • @TransactionAttribute can be applied to a bean or method
  • Default to REQUIRED
  • Other transaction attributes
MANDATORY     - Behaves like REQUIRED except if there is no transaction context, throws EJBTRansactionRequiredException
REQUIRED      - Client transaction context is propagated to the bean. If transaction context not available, start new transaction and commits it at the end of the business process (usually life-cycle of the bean)
REQUIRES_NEW  - Always starts new transaction context. If transaction context exist, suspends the parent transaction, and resumes it after committing the new transaction.
SUPPORTS      - If transaction context exist, use it, if not, work without transaction.
NOT_SUPPORTED  - If transaction context exists, suspends it and resumes at the end of the process.
NEVER          - If transaction context ecists, throw EJBException.

JBoss Transaction Configuration ⌘

  • jboss/service=TRansactionManager
  • What to focus on:
    • ResourceRollbackCount - due to resource failure
  • Heuristic decision
    • One resource lost connection with the other
    • The resource makes the decision to rollback or commit the transaction