I download the application and get a deadlock error. The script includes and updates the database at the same time by 10 different users. I looked online and still could not find a way to solve it. Here comes my sample deadlock code.
Can someone give me some tips to resolve the impasse? Thank you in advance.
SampleController:
onSubmit(userAccount)
{
sampleBO.testDeadLock(userAccount.getUserAccountId());
}
SampleBO:
public void testInsert(Long id)
{
sampleDAO.testInsert4(id);
}
public void testDeadLock(Long id)
{
testInsert(id);
sampleDAO.testUpdate4(id);
}
SampleDAO:
public void testInsert4(Long id)
{
StringBuffer sbSql = new StringBuffer();
sbSql.append(" INSERT INTO Test ");
sbSql.append(" ( ");
sbSql.append(" id, ");
sbSql.append(" note ");
sbSql.append(" ) ");
sbSql.append(" VALUES ");
sbSql.append(" (");
sbSql.append(""+id+",");
sbSql.append(" 'test' ");
sbSql.append(" )");
this.getSimpleJdbcTemplate().update(sbSql.toString());
}
public void testUpdate4(Long id)
{
StringBuffer sbSql = new StringBuffer();
sbSql.append(" UPDATE Test WITH(ROWLOCK) SET ");
sbSql.append(" note = 'test1111'");
sbSql.append(" WHERE id="+id);
this.getSimpleJdbcTemplate().update(sbSql.toString());
}
source
share