Lock wait timeout exceeded - How to solve?

My application is constantly presenting the following error: Lock wait timeout exceeded; try restarting transaction’.
This error appears on calling taskForm.completeTask().
I didn’t find any pattern for this occurance.

Please help to solve this problem.

Complete log return:
[2016-04-29T16:22:25.942-0300] [glassfish 4.1] [SEVERE] [] [org.camunda.bpm.engine.context] [tid: _ThreadID=196 _ThreadName=http-listener-1(38)] [timeMillis: 1461957745942] [levelValue: 1000] [[
ENGINE-16004 Exception while closing command context: ENGINE-03004
Exception while executing Database Operation 'DELETE_BULK deleteAuthorizationsForResourceId {resourceId=176d55ae-0e37-11e6-85d9-0050568265c7, resourceType=7}' with message '
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
### The error may involve org.camunda.bpm.engine.impl.persistence.entity.AuthorizationEntity.deleteAuthorizationsForResourceId-Inline
### The error occurred while setting parameters
### SQL: delete from ACT_RU_AUTHORIZATION      where          RESOURCE_TYPE_ = ?          AND RESOURCE_ID_ = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction'. Flush summary:  [
    INSERT HistoricVariableInstanceEntity[95d08cbc-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricVariableInstanceEntity[95d7b8b6-0e3f-11e6-85d9-0050568265c7]
    INSERT AuthorizationEntity[95da02af-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricVariableUpdateEventEntity[95d08cbd-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricVariableUpdateEventEntity[95d7b8b8-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricTaskInstanceEventEntity[95da02ad-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricDecisionOutputInstanceEntity[95d7b8b3-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricDecisionInstanceEntity[95d7b8b0-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricDecisionInputInstanceEntity[95d7b8b1-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricDecisionInputInstanceEntity[95d7b8b2-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricActivityInstanceEventEntity[BusinessRuleTask_0n5bkmi:95d7b8af-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricActivityInstanceEventEntity[ExclusiveGateway_1:95d7b8ba-0e3f-11e6-85d9-0050568265c7]
    INSERT HistoricActivityInstanceEventEntity[UserTask_2:95da02ab-0e3f-11e6-85d9-0050568265c7]
    INSERT TaskEntity[95da02ad-0e3f-11e6-85d9-0050568265c7]
    INSERT ByteArrayEntity[95d7b8b4-0e3f-11e6-85d9-0050568265c7]
    INSERT ByteArrayEntity[95d7b8b5-0e3f-11e6-85d9-0050568265c7]
    INSERT ByteArrayEntity[95d7b8b7-0e3f-11e6-85d9-0050568265c7]
    INSERT ByteArrayEntity[95d7b8b9-0e3f-11e6-85d9-0050568265c7]
    INSERT VariableInstanceEntity[95d7b8b6-0e3f-11e6-85d9-0050568265c7]
    DELETE VariableInstanceEntity[83d8a318-0e3f-11e6-85d9-0050568265c7]
    DELETE VariableInstanceEntity[959e8112-0e3f-11e6-85d9-0050568265c7]
    DELETE VariableInstanceEntity[959e8114-0e3f-11e6-85d9-0050568265c7]
    DELETE VariableInstanceEntity[959e8116-0e3f-11e6-85d9-0050568265c7]
    DELETE_BULK deleteByteArrayNoRevisionCheck 95d7b8b4-0e3f-11e6-85d9-0050568265c7
    DELETE TaskEntity[176d55ae-0e37-11e6-85d9-0050568265c7]
    UPDATE ExecutionEntity[176d5585-0e37-11e6-85d9-0050568265c7]
    UPDATE HistoricActivityInstanceEventEntity[UserTask_1:176d55ad-0e37-11e6-85d9-0050568265c7]
    UPDATE HistoricTaskInstanceEventEntity[176d55ae-0e37-11e6-85d9-0050568265c7]
    DELETE_BULK deleteAuthorizationsForResourceId {resourceId=176d55ae-0e37-11e6-85d9-0050568265c7, resourceType=7}
]

Hi Renato,

Could you please provide more details on the issue?
As you mentioned engine constantly throws a error, it would be really helpful if you could share the sequence of steps executed before taskForm.completeTask()

Also kindly share the version of the engine you are using.

Best Regards,
Deivarayan