本文整理匯總了Java中javax.transaction.UserTransaction.setTransactionTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java UserTransaction.setTransactionTimeout方法的具體用法?Java UserTransaction.setTransactionTimeout怎麽用?Java UserTransaction.setTransactionTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.transaction.UserTransaction
的用法示例。
在下文中一共展示了UserTransaction.setTransactionTimeout方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test4MultipleSetTimeOuts
import javax.transaction.UserTransaction; //導入方法依賴的package包/類
@Test
public void test4MultipleSetTimeOuts() throws Exception {
UserTransaction utx;
utx = new UserTransactionImpl();
utx.setTransactionTimeout(10);
utx.begin();
utx.setTransactionTimeout(8);
utx.setTransactionTimeout(6);
utx.setTransactionTimeout(2);
Thread.sleep(6000);
try {
utx.commit();
fail("TimeOut did not rollback the transaction");
} catch (Exception expected) {
}
}
示例2: test8CommitAfterTimeOut
import javax.transaction.UserTransaction; //導入方法依賴的package包/類
@Test
public void test8CommitAfterTimeOut() throws Exception {
Context ctx = cache.getJNDIContext();
DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
ds2.getConnection();
GemFireTransactionDataSource ds =
(GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
utx.begin();
Connection conn = ds.getConnection();
String sql = "create table newTable2 (id integer)";
Statement sm = conn.createStatement();
sm.execute(sql);
utx.setTransactionTimeout(30);
sql = "insert into newTable2 values (1)";
sm.execute(sql);
sql = "select * from newTable2 where id = 1";
ResultSet rs = sm.executeQuery(sql);
if (!rs.next()) {
fail("Transaction not committed");
}
sql = "drop table newTable2";
sm.execute(sql);
sm.close();
conn.close();
utx.setTransactionTimeout(1);
Thread.sleep(3000);
try {
utx.commit();
fail("exception did not occur on commit although transaction timed out");
} catch (Exception expected) {
}
}
示例3: test1One
import javax.transaction.UserTransaction; //導入方法依賴的package包/類
@Test
public void test1One() throws Exception {
UserTransaction utx = new UserTransactionImpl();
utx.begin();
Thread.sleep(2000);
utx.setTransactionTimeout(2);
utx.setTransactionTimeout(200);
utx.setTransactionTimeout(3);
Thread.sleep(5000);
// utx.commit();
}
示例4: test2SetTransactionTimeOut
import javax.transaction.UserTransaction; //導入方法依賴的package包/類
@Test
public void test2SetTransactionTimeOut() throws Exception {
UserTransaction utx = new UserTransactionImpl();
utx.begin();
utx.setTransactionTimeout(2);
System.out.println("Going to sleep");
Thread.sleep(6000);
utx.begin();
utx.commit();
}
示例5: test3ExceptionOnCommitAfterTimeOut
import javax.transaction.UserTransaction; //導入方法依賴的package包/類
@Test
public void test3ExceptionOnCommitAfterTimeOut() throws Exception {
UserTransaction utx;
utx = new UserTransactionImpl();
utx.setTransactionTimeout(2);
utx.begin();
Thread.sleep(4000);
try {
utx.commit();
fail("TimeOut did not rollback the transaction");
} catch (Exception expected) {
}
}
示例6: test5TimeOutBeforeBegin
import javax.transaction.UserTransaction; //導入方法依賴的package包/類
@Test
public void test5TimeOutBeforeBegin() throws Exception {
UserTransaction utx = new UserTransactionImpl();
utx.setTransactionTimeout(4);
utx.begin();
Thread.sleep(6000);
try {
utx.commit();
fail("TimeOut did not rollback the transaction");
} catch (Exception expected) {
}
}
示例7: test6CommitBeforeTimeOut
import javax.transaction.UserTransaction; //導入方法依賴的package包/類
@Test
public void test6CommitBeforeTimeOut() throws Exception {
UserTransaction utx = new UserTransactionImpl();
utx.begin();
utx.setTransactionTimeout(6);
Thread.sleep(2000);
utx.commit();
}
示例8: test7Commit
import javax.transaction.UserTransaction; //導入方法依賴的package包/類
@Test
public void test7Commit() throws Exception {
Context ctx = cache.getJNDIContext();
DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
ds2.getConnection();
GemFireTransactionDataSource ds =
(GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
utx.begin();
Connection conn = ds.getConnection();
String sql = "create table newTable1 (id integer)";
Statement sm = conn.createStatement();
sm.execute(sql);
utx.setTransactionTimeout(30);
Thread.sleep(5000);
utx.setTransactionTimeout(20);
utx.setTransactionTimeout(10);
sql = "insert into newTable1 values (1)";
sm.execute(sql);
utx.commit();
sql = "select * from newTable1 where id = 1";
ResultSet rs = sm.executeQuery(sql);
if (!rs.next()) {
fail("Transaction not committed");
}
sql = "drop table newTable1";
sm.execute(sql);
sm.close();
conn.close();
}
示例9: test9RollbackAfterTimeOut
import javax.transaction.UserTransaction; //導入方法依賴的package包/類
@Test
public void test9RollbackAfterTimeOut() throws Exception {
Context ctx = cache.getJNDIContext();
DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
Connection conn2 = ds2.getConnection();
GemFireTransactionDataSource ds =
(GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
utx.begin();
Connection conn = ds.getConnection();
String sql = "create table newTable3 (id integer)";
Statement sm = conn.createStatement();
sm.execute(sql);
utx.setTransactionTimeout(30);
sql = "insert into newTable3 values (1)";
sm.execute(sql);
sql = "select * from newTable3 where id = 1";
ResultSet rs = sm.executeQuery(sql);
if (!rs.next()) {
fail("Transaction not committed");
}
sql = "drop table newTable3";
sm.execute(sql);
sm.close();
conn.close();
conn2.close();
utx.setTransactionTimeout(1);
Thread.sleep(3000);
try {
utx.rollback();
fail("exception did not occur on rollback although transaction timed out");
} catch (Exception expected) {
}
}