为什么部署到服务器上之后,数据一多就报死锁的错误?

关于死锁,我用的是springmvc框架,事物在service层创建
大概的操作是这样的:学生表student,选课表elective
选课表与考生表关联的
boolean checkElective(string sids, string state){
//sids是学生id的拼接,大概像1,2,3这样
//把每一个id转成integer,具体代码先省略  
integer[] sid = ....;

list<elective> electives = new arrayList<elective>();
list<student> students = new arrayList<students>();
foreach(int studentid : sid){
Student student = getById(studentid);
student.setTime(time);
students.add(student);

Elective elective = getEleByStudent(studentid);
elective.setState('成功');
electives.add(elective);
}
baseDao.save(electives) && baseDao.save(students);
}

项目的大概意思是这样的,测试的时候没有问题,也没有报错。
但是部署到服务器上之后,数据一多就报死锁的错误
org.springframework.dao.ConnotAcquireLockException:Could not execute JDBC batch update;
是报错在students保存的时候
求教各位大神

www说
浏览 102回答 1
1回答

慕妹3146593

死锁是两个线程互相等待造成的,你知道这一点吧,学习这个学的是思路不是代码。baseDao.save(students);&nbsp; 同步那些修改变量的代码,使用synchronized关键字同步方法或代码。 同步之后就会只有一个线程访问了。
打开App,查看更多内容
随时随地看视频慕课网APP