關于死鎖,我用的是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保存的時候求教各位大神
1 回答

慕妹3146593
TA貢獻1820條經驗 獲得超9個贊
死鎖是兩個線程互相等待造成的,你知道這一點吧,學習這個學的是思路不是代碼。
baseDao.save(students); 同步那些修改變量的代碼,使用synchronized關鍵字同步方法或代碼。 同步之后就會只有一個線程訪問了。
- 1 回答
- 0 關注
- 75 瀏覽
添加回答
舉報
0/150
提交
取消