当前位置: 首页>>代码示例>>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;未经允许,请勿转载。