當前位置: 首頁>>代碼示例>>Java>>正文


Java UserTransaction.setTransactionTimeout方法代碼示例

本文整理匯總了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) {
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:17,代碼來源:TransactionTimeOutJUnitTest.java

示例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) {
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:34,代碼來源:TransactionTimeOutJUnitTest.java

示例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();
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:12,代碼來源:TransactionTimeOutJUnitTest.java

示例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();
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:11,代碼來源:TransactionTimeOutJUnitTest.java

示例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) {
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:14,代碼來源:TransactionTimeOutJUnitTest.java

示例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) {
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:13,代碼來源:TransactionTimeOutJUnitTest.java

示例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();
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:9,代碼來源:TransactionTimeOutJUnitTest.java

示例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();
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:31,代碼來源:TransactionTimeOutJUnitTest.java

示例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) {
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:35,代碼來源:TransactionTimeOutJUnitTest.java


注:本文中的javax.transaction.UserTransaction.setTransactionTimeout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。