批量更新时死锁

时间:2016-11-09 09:17:23

标签: java mysql

在更新MySql中的记录期间,它会抛出

  

连接中的批量更新异常rollbackjava.sql.BatchUpdateException:尝试获取锁定时发现死锁;尝试重新启动交易。

这是样品批次:

 
| CAMPAIGN_EMAIL_LOG_ID | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| SCHEDULE_ID_ID        | int(11)          | YES  |     | NULL    |                |
| CAMPAIGN_ID           | int(11)          | YES  | MUL | NULL    |                |
| TEMPLATE_ID           | int(11)          | YES  |     | NULL    |                |
| CONTACT_ID            | int(11)          | YES  | MUL | NULL    |                |
| LIST_ID               | varchar(18)      | YES  |     | NULL    |                |
| MAIL_READ             | datetime         | YES  |     | NULL    |                |
| OPT_OUT               | datetime         | YES  |     | NULL    |                |
| MAIL_BOUNCE           | int(11)          | YES  |     | NULL    |                |
| URL_VISITED           | datetime         | YES  |     | NULL    |                |
| MAIL_SENT             | datetime         | YES  | MUL | NULL    |                |
| DESCRIPTION           | text             | YES  |     | NULL    |                |
| TIME_OPENED           | time             | YES  |     | NULL    |                |
| LAST_OPENED           | date             | YES  |     | NULL    |                |
| TIME_LAST_OPENED      | time             | YES  |     | NULL    |                |
| NO_OF_COUNT           | int(20)          | YES  |     | NULL    |                |
| CC                    | varchar(255)     | YES  |     | NULL    |                |
| BCC                   | varchar(255)     | YES  |     | NULL    |                |
| EVENT                 | varchar(50)      | YES  |     | NULL    | 

这是CAMPAIGN_ID (MUL)

的表格结构
if(event != null && event.toLowerCase().indexOf("bounce") != -1) 
{
    sqlQuery = "UPDATE CM_CONTACT_DETAILS SET SEND_GRID_BOUNCE = 'Y',
                SEND_GRID_BOUNCE_REASON = \""+reason+"\"  
                WHERE EMAIL_IDS = '"+email+"'";
    batchupdateList.add(sqlQuery);
    sqlQuery = "UPDATE CM_LEAD_DETAILS SET SEND_GRID_BOUNCE = 'Y' ,
                SEND_GRID_BOUNCE_REASON = \""+reason+"\"  
                WHERE EMAIL_IDS = '"+email+"'";
    batchupdateList.add(sqlQuery);
    BounceUtil.addBounceSpamRemarks(contactId,email,"bounce","cm");
} else 
{
    sqlQuery = "UPDATE CM_CAMPAIGN_EMAIL_LOG 
                SET EVENT=\""+event+"\" 
                WHERE CONTACT_ID IN( "+mainId+")  AND TEMPLATE_ID = "
              +templateId.trim()+" AND CAMPAIGN_ID = "+campaignId.trim();
    CommonUtil.updateLastContactedField(contactId,"emailReceived");//ZCUB-20150915-176
    if(event != null && (event.toLowerCase().indexOf("processed") != -1))
    { 
        sqlQuery=sqlQuery+" AND EVENT IS NULL";
    }   
    //Event_Sequence_Issue start
    batchupdateList.add(sqlQuery);
    if(event!=null && event.toLowerCase().indexOf("spam") != -1) 
    {
        sqlQuery = "UPDATE CM_CONTACT_DETAILS SET SEND_GRID_SPAM = 'Y'
                    WHERE EMAIL_IDS = '"+email+"'";
       batchupdateList.add(sqlQuery);
       sqlQuery = "UPDATE CM_LEAD_DETAILS SET SEND_GRID_SPAM = 'Y' 
                   WHERE EMAIL_IDS = '"+email+"'";
       batchupdateList.add(sqlQuery);
       BounceUtil.addBounceSpamRemarks(contactId,email,"spam","cm");
    }
}

所以我想知道Get-ADUSer -Filter * -Properties givenName, sn, SamAccountName | Select givenName, sn, SamAccountName 是否导致死锁。如果是,那么我如何对我的代码进行排序,以便不会发生此死锁。

这是我的代码:

npm cache clean

0 个答案:

没有答案