
复制//验证思路参考自:https://blog.csdn.net/sunbo94/article/details/79409298 //Connection设置 autoCommit=false private static final ThreadLocal<Connection> connectionThreadLocal=new ThreadLocal<>(); private static class InnerRunner implements Runnable{ @Override public void run() { //其他代码省略... String insertSql="insert into user(id,高并name) value("+RunnerIndex+","+RunnerIndex+")"; statement=connectionThreadLocal.get().createStatement(); statement.executeUpdate(insertSql); System.out.println(RunnerIndex+" is running"); //让特定的线程执行回滚,源码库用来验证事务之间的WordPress模板发服影响 if (RunnerIndex==3){ //模拟异常时耗时增加 Thread.sleep(100); //从threadlocal里拿连接对象 connectionThreadLocal.get().rollback(); System.out.println("3 rollback"); }else{ //从threadlocal里拿连接对象 connectionThreadLocal.get().commit(); System.out.println(RunnerIndex +" commit"); } } } 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.云服务器


相关文章


精彩导读
热门资讯
关注我们
