当前位置: 首页 > news >正文

做美食下载什么网站字体 wordpress

做美食下载什么网站,字体 wordpress,施工企业合规风险识别与管理,赣州网站建设公司java pojo使用大多数嵌套事务是使用EJB实现的#xff0c;现在我们尝试在POJO上实现嵌套事务。 在这里#xff0c;我们使用了ThreadLocal的功能。 了解嵌套事务 事务可以嵌套在另一个内部。 因此#xff0c;内部事务或外部事务可以回滚或提交#xff0c;而不会影响其他事务… java pojo使用 大多数嵌套事务是使用EJB实现的现在我们尝试在POJO上实现嵌套事务。 在这里我们使用了ThreadLocal的功能。 了解嵌套事务 事务可以嵌套在另一个内部。 因此内部事务或外部事务可以回滚或提交而不会影响其他事务。 创建新事务后它将进入外部事务。 一旦内部事务以提交或回滚的方式完成外部事务就可以执行提交或回滚而与内部事务无关。 首先关闭最内部的事务然后继续进行外部事务。 使用简单POJO实施 创建界面如下 importjava.sql.Connection;publicinterfaceTransactionManager {Connection getConnection();voidbeginTransaction();void commit();void rollback(); } 创建事务管理器类如下所示 importjava.sql.Connection; importjava.sql.DriverManager; importjava.sql.SQLException; importjava.util.Stack;publicclassTransactionManagerStackImplimplementsTransactionManager {private StackConnectionconnections new StackConnection();Overridepublic Connection getConnection() {if (connections.isEmpty()) {this.addConn();}returnconnections.peek();}OverridepublicvoidbeginTransaction() {this.addConn();}Overridepublicvoid commit() {try {if (connections.peek() ! null !connections.peek().isClosed()) {System.out.println(connections.peek().toString() --Commit---);connections.peek().commit();connections.pop().close();}} catch (SQLException e) {e.printStackTrace();}}Overridepublicvoid rollback() {try {if (connections.peek() ! null !connections.peek().isClosed()) {System.out.println(connections.peek().toString() --Rollback---);connections.peek().rollback();connections.pop().close();}} catch (SQLException e) {e.printStackTrace();}}privatevoidaddConn() {try {Connection con this.getMysqlConnection();con.setAutoCommit(false);connections.push(con);System.out.println(con.toString() --Conection---);} catch (SQLException e) {e.printStackTrace();}}private Connection getMysqlConnection() {returngetConnection(com.mysql.jdbc.Driver, jdbc:mysql://localhost:3306/testdb, test, test12345);}private Connection getConnection(String driver, String connection,String user, String password) {try {Class.forName(driver);returnDriverManager.getConnection(connection, user, password);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();}returnnull;} } 在这里我们创建了一个堆栈 private StackConnection connections new StackConnection(); 由于事务创建为LIFO堆栈因此我们使用了Java API中的Stack来维护每个事务的连接 public void beginTransaction() 开始事务以开始新事务并将连接添加到堆栈。 AutoCommit已设置为false public Connection getConnection() 获取当前事务的连接。 如果不存在它将创建并添加到堆栈中 public void commit() 提交当前事务并关闭连接该连接也已从堆栈中删除 public void rollback() 回滚当前事务并关闭连接该连接也已从堆栈中删除。 上面的TransactionManagerStackImpl类将为单线程创建嵌套事务。 多线程嵌套事务 对于多线程应用程序每个线程都有独立的事务和嵌套事务。 我们提出使用ThreadLocal来管理连接堆栈。 importjava.sql.Connection;publicclassTransactionManagerThreadLocalimplementsTransactionManager {privatestaticfinalThreadLocalTransactionManagertranManager newThreadLocalTransactionManager() {protectedTransactionManagerinitialValue() {System.out.println(this.toString() --Thread Local Initialize--);returnnewTransactionManagerStackImpl();}};OverridepublicvoidbeginTransaction() {tranManager.get().beginTransaction();}Overridepublicvoid commit() {tranManager.get().commit();}Overridepublicvoid rollback() {tranManager.get().rollback();}Overridepublic Connection getConnection() {returntranManager.get().getConnection();} } 在这里我们初始化TransactionManagerStackImpl以在线程内部创建嵌套事务。 测试中 为了进行上述测试请提交内部事务并回滚外部事务。 importjava.sql.Connection;publicclassNestedMainimplements Runnable {privateintv 0;private String name;NestedMain(int v, String name) {this.v v;this.name name;}publicstaticvoid main(String[] args) throws Exception{for (inti 0; i 3; i) {NestedMain main newNestedMain(i * 10, Ravi i);new Thread(main).start();}}Overridepublicvoid run() {try {TransactionManagerThreadLocal local newTransactionManagerThreadLocal();// Transaction 1 ( outer )local.beginTransaction();Connection con local.getConnection();String sql INSERT INTO test_tran (emp_id, name) VALUES (1v, namev);this.insert(con, sql);// Transaction 2 ( Inner )local.beginTransaction();con local.getConnection();sql INSERT INTO test_tran (emp_id, name) VALUES (2v, namev);this.insert(con, sql);local.commit(); // Committing 2local.rollback(); // Rollback 1 Outer} catch (Exception e) {e.printStackTrace();}结果 com.ttit.TransactionManagerThreadLocal$11270b73--Thread Local Initialize-- com.ttit.TransactionManagerThreadLocal$11270b73--Thread Local Initialize-- com.ttit.TransactionManagerThreadLocal$11270b73--Thread Local Initialize-- com.mysql.jdbc.JDBC4Connection10dd1f7--Conection--- com.mysql.jdbc.JDBC4Connection1813fac--Conection--- com.mysql.jdbc.JDBC4Connection136228--Conection--- com.mysql.jdbc.JDBC4Connection1855af5--Conection--- com.mysql.jdbc.JDBC4Connectione39a3e--Conection--- com.mysql.jdbc.JDBC4Connection1855af5--Commit--- com.mysql.jdbc.JDBC4Connectione39a3e--Commit--- com.mysql.jdbc.JDBC4Connection9fbe93--Conection--- com.mysql.jdbc.JDBC4Connection9fbe93--Commit--- com.mysql.jdbc.JDBC4Connection10dd1f7--Rollback--- com.mysql.jdbc.JDBC4Connection1813fac--Rollback--- com.mysql.jdbc.JDBC4Connection136228--Rollback--- 名称 emp_id 拉维220 220 拉维00 20 拉维110 210 回滚内部事务并提交外部事务时 com.ttit.TransactionManagerThreadLocal$11270b73--Thread Local Initialize-- com.ttit.TransactionManagerThreadLocal$11270b73--Thread Local Initialize-- com.ttit.TransactionManagerThreadLocal$11270b73--Thread Local Initialize-- com.mysql.jdbc.JDBC4Connection9f2a0b--Conection--- com.mysql.jdbc.JDBC4Connection136228--Conection--- com.mysql.jdbc.JDBC4Connection1c672d0--Conection--- com.mysql.jdbc.JDBC4Connection9fbe93--Conection--- com.mysql.jdbc.JDBC4Connection1858610--Conection--- com.mysql.jdbc.JDBC4Connection9fbe93--Rollback--- com.mysql.jdbc.JDBC4Connection1858610--Rollback--- com.mysql.jdbc.JDBC4Connection1a5ab41--Conection--- com.mysql.jdbc.JDBC4Connection1a5ab41--Rollback--- com.mysql.jdbc.JDBC4Connection9f2a0b--Commit--- com.mysql.jdbc.JDBC4Connection136228--Commit--- com.mysql.jdbc.JDBC4Connection1c672d0--Commit--- 名称 emp_id 拉维00 10 拉维220 120 拉维110 110 资源 了解ThreadLocal背后的概念 翻译自: https://www.javacodegeeks.com/2013/12/java-nested-transaction-using-threadlocal-in-pojo.htmljava pojo使用
http://www.huolong8.cn/news/51293/

相关文章:

  • 网站会员系统模板北京网站设计十年乐云seo
  • 网站一般都是用什么软件做的深圳营销网站建设联系方式
  • 简单项目计划书网站优化计划
  • 建设企业网站方案营销的方法手段有哪些
  • 长沙建网站理wordpress cms
  • 网页小游戏斗地主如何评估一个网站seo的优异程度
  • 泸州建设局网站创建自己的网页要多少钱
  • wordpress 动漫 主题下载用广州seo推广获精准访问量
  • 专业建设网站企业有那些网站可以做推广
  • 什么叫做网站维护app源码购买
  • 注册网站需要什么程序临沂市住房和城乡建设厅网站
  • 天津网站建设求职简历万网关网站三次
  • 创建网站需要注意的问题WordPress 图标字体
  • 网站备案都审核什么资料商企通三合一网站建设
  • 临沂外贸国际网站建设网站开发试验报告
  • 网站显示建设中页面wordpress调用评论框
  • 高中课程免费教学网站wordpress移动底部导航菜单
  • 商城开发分销系统青岛seo网络优化公司
  • python做公司网站电商网站开发服务
  • 企业进行网站建设的方式有产品软文范例
  • 东营北京网站建设百度竞价广告收费标准
  • 用wordpress可以做出什么网站佛山市三山新城建设局网站
  • 论述网站建设及运营流程小程序代理公司
  • 网站搭建教程零基础网站设计与制作的基本步骤
  • 大理网站开发网页设计如何制作背景
  • 网站建设这个工作怎么样贺州市八步区乡镇建设局网站
  • 德尔普网站建设北京市保障性住建设投资中心网站
  • 网站中的搜索框怎么做哪里有软件开发培训机构
  • xp网站建设网店装修图
  • 百度如何网站淘宝运营培训班