WebLogic Server中CMP實體bean的性能調優[7] 性能測試工具
下面基于Cactus的測試驗證了該行為。假定一個Person CMP bean是利用樂觀并發部署的,并且cache-between-transaction被設置為true:
...
public class OptimisticLockingTest extends ServletTestCase {
private UserTransaction tx;
protected void setUp() throws Exception {
super.setUp();
Context context = new InitialContext();
this.tx = (UserTransaction)context
.lookup("javax/transaction/UserTransaction");
}
public void testCacheBetweenTransactions() throws Exception {
PersonLocalHome localHome = (PersonLocalHome)Locator
.getLocalHome(PersonLocalHome.JNDI_NAME);
// create record via CMP in first transaction
this.tx.begin();
PersonLocal local = localHome.create();
local.setName("John");
Long pk = local.getPrimaryKey();
this.tx.commit();
// update some field(s) via direct JDBC call in another
// transaction. Assume that updatePersonNameViaJdbc()
// method will update version column as well
String newName = "Paul";
this.tx.begin();
updatePersonNameViaJdbc(pk, newName);
this.tx.commit();
// find CMP again and try to update name in yet
// another transaction
原文轉自:http://www.anti-gravitydesign.com