a JMS provider javax.transaction.xa.XAResource interface, the implements the javax.jms.XAConnection and the javax.jms.XASession interface.
5 Common TransactionManager
5.1 EJB Transaction Options:
NotSupported
If the method is called within a transaction, this transaction is suspended during the time of the method execution.
Required
If the method is called within a transaction, the method is executed in the scope of this transaction; otherwise, a new transaction is started for the execution of the method and committed before the method result is sent to the caller.
RequiresNew
The method will always be executed within the scope of a new transaction. The new transaction is started for the execution of the method, and committed before the method result is sent to the caller. If the method is called within a transaction, this transaction is suspended before the new one is started and resumed when the new transaction has completed.
Mandatory
The method should always be called within the scope of a transaction, else the container will throw the TransactionRequired exception.
Supports
The method is invoked within the caller transaction scope; if the caller does not have an associated transaction, the method is invoked without a transaction scope.
Never
The client is required to call the bean without any transaction context; if it is not the case, a java.rmi.RemoteException is thrown by the container.
5.2 Spring transaction:
Transaction isolation: The degree of isolation this transaction has from the work of other transactions. For example, can this transaction see uncommitted writes from other transactions? avaliable options:
ISOLATION_DEFAULT
ISOLATION_READ_UNCOMMITTED
ISOLATION_READ_COMMITTED
ISOLATION_REPEATABLE_READ
ISOLATION_SERIALIZABLE
Transaction propagation: Normally all code executed within a transaction scope will run in that transaction. However, there are several options specifying behavior if a transactional method is executed when a transaction context already exists: For example, simply running in the existing transaction (the most common case); or suspending the existing transaction and creating a new transaction. Spring offers the transaction propagation options familiar from EJB CMT. avaliable options:
PROPAGATION_MANDATORY
PROPAGATION_NESTED
PROPAGATION_NEVER
PROPAGATION_NOT_SUPPORTED
PROPAGATION_REQUIRED
PROPAGATION_REQUIRES_NEW
PROPAGATION_SUPPORTS
Transaction timeout: How long this transaction may run before timing out (automatically being rolled back by the underlying transaction infrastructure).
Read-only status: A read-only transaction does not modify any data. Read-only transactions can be a useful optimization in some cases (such as when using Hibernate).
6 transaction for web service
Protocol specifications:
WS-Transaction
OASIS Business Transaction Protocol (BTP)
Java API
JAXTX (JSR-156)
~
" inverts a bit
pattern.
& The bitwise &
operator performs a bitwise AND
operation.
^ The bitwise ^
operator performs a bitwise exclusive OR
operation.
| The bitwise |
operator performs a bitwise inclusive OR
operation.
^
can swap two variables without using an intermediate,
temporary variable which is useful if you are short on available RAM or
want that sliver of extra speed.
Usually, when not using ^
, you will do:
temp = a;
a = b;
b = temp;
Using ^
, no "temp" is needed:
a ^= b;
b ^= a;
a ^= b;
This will swap "a" and "b" integers. Both must be integers.
// These are my masks
private static final int MASK_DID_HOMEWORK = 0x0001;
private static final int MASK_ATE_DINNER = 0x0002;
private static final int MASK_SLEPT_WELL = 0x0004;
// This is my current state
private int m_nCurState;
To set my state, I use the bitwise OR operator:
// Set state for'ate dinner' and 'slept well' to 'on'
m_nCurState = m_nCurState | (MASK_ATE_DINNER | MASK_SLEPT_WELL);
Notice how I 'or' my current state in with the states that I want to turn 'on'. Who knows what my current state is and I don't want to blow it away.
To unset my state, I use the bitwise AND operator with the complement operator:
// Turn off the 'ate dinner' flag
m_nCurState = (m_nCurState & ~MASK_ATE_DINNER);
To check my current state, I use the AND operator:
// Check if I did my homework
if (0 != (m_nCurState & MASK_DID_HOMEWORK)) {
// yep
} else {
// nope...
}
Why do I think this is interesting? Say I'm designing an interface that sets my state. I could write a method that accepts three booleans:
void setState( boolean bDidHomework, boolean bAteDinner, boolean bSleptWell);
Or, I could use a single number to represent all three states and pass a single value:
void setState( int nStateBits);
If you choose the second pattern you'll be very happy when decide to add another state - you won't have to break existing impls of your interface.
我們可以通過配置XML文件來完成cache相關的所有對象聲明。
簡而言之,就是利用java reflection和AOP的技術就不用寫聲明cache的代碼了。Pros:
1, reduce configuration xml files
2, readable by self-documenting
Cons:
1, it adds deployment context to classes, which should be generic enough.
2, interfere with design principles such as IOC and dependency injection, because you need to introduce imports
Usage (annotation works only when handled by related annotation processor):