并发量很大,出现了死锁,各位有没遇到过这样的问题?
下面贴出代码,只做了插入操作,插入也会出现死锁吗?
public class ICDatabase { Object mainObject = null; public void save(Set mainTable) throws InfoCageException { Transaction transaction = null; Session session = null; try { session = HibernateSessionFactory.currentSession(); transaction = session.beginTransaction(); Iterator iterator = mainTable.iterator(); if (iterator != null) { while (iterator.hasNext()) { mainObject = iterator.next(); session.save(mainObject); clear(); } transaction.commit(); } } catch (Exception exception) { try { if (transaction != null) transaction.rollback(); } catch (Exception e) { InfoCageLogging.writeError(e, InfoCodes.ROLLBACK_ERROR); } throw new InfoCageException(ErrorCodes.DATABASE_UPDATE_ERROR, exception); } finally { if (session != null) { try { HibernateSessionFactory.closeSession(); clear(); } catch (Exception e) { InfoCageLogging.writeError(e, InfoCodes.CLOSE_SESSION_ERROR); } } } } void clear() { mainObject = null; } }
|
在事务提交时发生这样的错误:
事务(进程 ID 84)与另一个进程已被死锁在 lock 资源上,且该事务已被选作死锁牺牲品。请重新运行该事务。