问一个mysql事务并发的问题 理论上讲表应该是读取更改过的。你应该是使用了hibernate类似的持久化方式。首先不使用持久化,直接连数据库测试多线程,查看A的读取结果。应该就是正常情况。这说明是持久化过程有延迟,可能是缓存机制造成的,查看配置文件,取消缓存机制再测。只要找到问题根源就能找到解决办法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的是sping+jdbc,就是jdbcTemplate,应该不是延迟的问题 内容太多,不是一句两句能说清楚的。你可以看看事物的级别。 再看看数据库原理关于锁的部分,事物级别:(看名字应该就能猜出来有什么不一样吧) Read UncommittedRead CommittedRepeatable ReadSerializable 嗯,上下代码public void taxStuGuidCase(StuTestAnswerObj stuTestAnswerObj) throws Exception{ // 如果把下行这行代码注掉,下面取的id都是新的,不知为什么? List<PreCaseObj> preCaseObjList = DAOTool.getDAO(PreCaseDAO.class).findPreCaseObjsByGuidcaseId(2); for(int i=0;i<10;i++){ int id = NLLDDAOTool.getAutoID(StuTestQuestionObj.tablename); System.out.println("---------newId "+Thread.currentThread().getId() + " " + id); }} 注掉的代码是查询的另外一个单表,注掉前后结果如下,其中22、23、24是线程号注掉那行代码时结果如下,是正确的,取的id是不同的---22 test 0 startINFO http-8080-1 org.springframework.aop.framework.DefaultAopProxyFactory - CGLIB2 available: proxyTargetClass feature enabled---23 test 0 start---24 test 0 startINFO http-8080-1 org.springframework.jdbc.datasource.JdbcTransactionObjectSupport - JDBC 3.0 Savepoint class is available------24 taxStuGuidCase start------23 taxStuGuidCase start------22 taxStuGuidCase start---------newId 24 23845---------newId 24 23846---------newId 24 23847---------newId 24 23848---------newId 24 23849---------newId 24 23850---------newId 24 23851---------newId 24 23852---------newId 24 23853---------newId 24 23854------24 taxStuGuidCase end---------newId 22 23855---------newId 22 23856---------newId 22 23857---------newId 22 23858---------newId 22 23859---------newId 22 23860---------newId 22 23861---------newId 22 23862---------newId 22 23863---------newId 22 23864------22 taxStuGuidCase end---24 test 0 end---------newId 23 23865---------newId 23 23866---------newId 23 23867不注掉那行代码时取的重复---22 test 0 startINFO http-8080-1 org.springframework.aop.framework.DefaultAopProxyFactory - CGLIB2 available: proxyTargetClass feature enabled---23 test 0 start---24 test 0 startINFO http-8080-2 org.springframework.jdbc.datasource.JdbcTransactionObjectSupport - JDBC 3.0 Savepoint class is available------23 taxStuGuidCase start------24 taxStuGuidCase start------22 taxStuGuidCase start---------newId 23 25225---------newId 23 25226---------newId 23 25227---------newId 23 25228---------newId 23 25229---------newId 23 25230---------newId 23 25231---------newId 23 25232---------newId 23 25233---------newId 23 25234------23 taxStuGuidCase end---------newId 24 25225---------newId 24 25226---------newId 24 25227---------newId 24 25228---------newId 24 25229---------newId 24 25230---------newId 24 25231---------newId 24 25232---------newId 24 25233---------newId 24 25234------24 taxStuGuidCase end---23 test 0 end---------newId 22 25225---------newId 22 25226---------newId 22 25227---------newId 22 25228---------newId 22 25229---------newId 22 25230---------newId 22 25231 你的Spring事务应该配置的是未提交读,即读取数据时不受锁得限制。用楼上的方式试试,或者修改事务配置。 需要看INNODB、MYIsam、事务、锁(读锁、写锁)。 写事务会上锁,读事务也给不会上锁,你这种情况,好像只能re-load!个人观点,仅供参考! 1.数据库事务是有隔离级别的。 看看你出现的状况满足数据库事务的那个隔离级别。2.如果你查询出来的数据,不想被其他事务修改,就要将查询出来的记录锁住。 使用 select for update。3.如果是频繁操作,注意性能问题。 内存溢出 请教 急 求一个正则表达式的写法 请帮帮小弟一个忙 ear 部署在weblogic的问题(jsp compiler error) 谢谢 在applet中如何关闭IE窗口? 我的窗口为什么不显示按钮??? 一个方法调用的问题.谢谢. 想问一问JTOOLBAR如何加上背景,送分了吧。。。 一个public class A,一个class B, 在class B中实现画图的功能,在public class A中 实例化B 2个类要怎么联系起来我有个例子,可以帮我写 求高手点拨一个Socket通信软件的问题解决方案. UDP传输数据包丢失,如何解决 求助一道实际题目
Read Uncommitted
Read Committed
Repeatable Read
Serializable
public void taxStuGuidCase(StuTestAnswerObj stuTestAnswerObj) throws Exception{
// 如果把下行这行代码注掉,下面取的id都是新的,不知为什么?
List<PreCaseObj> preCaseObjList = DAOTool.getDAO(PreCaseDAO.class).findPreCaseObjsByGuidcaseId(2); for(int i=0;i<10;i++){
int id = NLLDDAOTool.getAutoID(StuTestQuestionObj.tablename);
System.out.println("---------newId "+Thread.currentThread().getId() + " " + id);
}
}
---22 test 0 start
INFO http-8080-1 org.springframework.aop.framework.DefaultAopProxyFactory - CGLIB2 available: proxyTargetClass feature enabled
---23 test 0 start
---24 test 0 start
INFO http-8080-1 org.springframework.jdbc.datasource.JdbcTransactionObjectSupport - JDBC 3.0 Savepoint class is available
------24 taxStuGuidCase start
------23 taxStuGuidCase start
------22 taxStuGuidCase start
---------newId 24 23845
---------newId 24 23846
---------newId 24 23847
---------newId 24 23848
---------newId 24 23849
---------newId 24 23850
---------newId 24 23851
---------newId 24 23852
---------newId 24 23853
---------newId 24 23854
------24 taxStuGuidCase end
---------newId 22 23855
---------newId 22 23856
---------newId 22 23857
---------newId 22 23858
---------newId 22 23859
---------newId 22 23860
---------newId 22 23861
---------newId 22 23862
---------newId 22 23863
---------newId 22 23864
------22 taxStuGuidCase end
---24 test 0 end
---------newId 23 23865
---------newId 23 23866
---------newId 23 23867不注掉那行代码时取的重复
---22 test 0 start
INFO http-8080-1 org.springframework.aop.framework.DefaultAopProxyFactory - CGLIB2 available: proxyTargetClass feature enabled
---23 test 0 start
---24 test 0 start
INFO http-8080-2 org.springframework.jdbc.datasource.JdbcTransactionObjectSupport - JDBC 3.0 Savepoint class is available
------23 taxStuGuidCase start
------24 taxStuGuidCase start
------22 taxStuGuidCase start
---------newId 23 25225
---------newId 23 25226
---------newId 23 25227
---------newId 23 25228
---------newId 23 25229
---------newId 23 25230
---------newId 23 25231
---------newId 23 25232
---------newId 23 25233
---------newId 23 25234
------23 taxStuGuidCase end
---------newId 24 25225
---------newId 24 25226
---------newId 24 25227
---------newId 24 25228
---------newId 24 25229
---------newId 24 25230
---------newId 24 25231
---------newId 24 25232
---------newId 24 25233
---------newId 24 25234
------24 taxStuGuidCase end
---23 test 0 end
---------newId 22 25225
---------newId 22 25226
---------newId 22 25227
---------newId 22 25228
---------newId 22 25229
---------newId 22 25230
---------newId 22 25231
你这种情况,好像只能re-load!
个人观点,仅供参考!
看看你出现的状况满足数据库事务的那个隔离级别。2.如果你查询出来的数据,不想被其他事务修改,就要将查询出来的记录锁住。
使用 select for update。3.如果是频繁操作,注意性能问题。