本文整理汇总了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) {
}
}