cancel
Showing results for 
Search instead for 
Did you mean: 

MessageEntity[] was updated by another transaction concurren

javatech
Champ in-the-making
Champ in-the-making
Hi
iam facing  org.activiti.engine.ActivitiOptimisticLockingException:
MessageEntity[18764] was updated by another transaction concurrently

while testing through JMeter for load testing with config as

<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
   <property name="dataSource" ref="dataSource" />
   <property name="transactionManager" ref="transactionManager" />
   <property name="databaseSchemaUpdate" value="false" />
   <property name="jobExecutorActivate" value="true" />
   <property name="jpaEntityManagerFactory" ref="entityManagerFactory" />
   <property name="jpaHandleTransaction" value="true" />
   <property name="jpaCloseEntityManager" value="true" />
   
   </bean>

if number of threads more then 25, the above expectation throwing.
Any solution for this problem. Help really appreciated .

Image attached for reference.

org.activiti.engine.ActivitiOptimisticLockingException:
MessageEntity[18764] was updated by another transaction concurrently
   at org.activiti.engine.impl.db.DbSqlSession.flushUpdates(DbSqlSession.java:452)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:348)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:149)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:105)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable.run(AcquireJobsRunnable.java:57)
   at java.lang.Thread.run(Unknown Source)
6 REPLIES 6

trademak
Star Contributor
Star Contributor
Hi,

Are you using async tasks? Or other jobs that are not listed in the attached diagram?
Are you testing with multiple Activiti Engines?

Best regards,

javatech
Champ in-the-making
Champ in-the-making
Yes its Asyn Task.

iam using the below code to init process.

Registration reg =  new Registration();
reg.setLoginInfo(loginDetails);
reg.setProjInfo(projInfo);

ServicesRequest serviceReq = new ServicesRequest();
serviceReq.setCgass(cgass);
serviceReq.setCodenizant(codenizant);

reg.setServicesReq(serviceReq);

System.out.println(reg.getLoginInfo().getUserId());


java.util.Map<String, Object> prop = new java.util.HashMap<String, Object>();
prop.put("userReg", reg);

ProcessInstance processInstance = UnifiedProcessEngine.getRuntimeService()
  .startProcessInstanceByKey("ApprovalProcess", prop);

package com.cts.bpmn.activiti.core.engine;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.util.zip.ZipInputStream;
import javax.xml.bind.JAXBException;

import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.cts.bpmn.activiti.Utils.FileUtil;
import com.cts.bpmn.activiti.exception.ActivitiError;
import com.cts.bpmn.activiti.exception.ActivitiException;
import com.cts.bpmn.activiti.logger.ActivitiLogger;

import static com.cts.bpmn.activiti.core.engine.UPEngineConstants.*;

public class UnifiedProcessEngine {

private static RuntimeService runtimeService = null;
private static RepositoryService repositoryService = null;
private static TaskService taskService = null;
private static ManagementService managementService = null;
private static IdentityService identityService = null;
private static HistoryService historyService = null;
private static FormService formService = null;
private static Deployment deploymentResourceInfo = null;

private static ActivitiLogger LOG = ActivitiLogger
   .getActivitiLogger(UnifiedProcessEngine.class.getName());

private UnifiedProcessEngine() {

}

public static RuntimeService getRuntimeService() {
  return runtimeService;
}

public static RepositoryService getRepositoryService() {
  return repositoryService;
}

public static TaskService getTaskService() {
  return taskService;
}

public static ManagementService getManagementService() {
  return managementService;
}

public static IdentityService getIdentityService() {
  return identityService;
}

public static HistoryService getHistoryService() {
  return historyService;
}

public static FormService getFormService() {
  return formService;
}

public static void initDeploy() {

  LOG.logDebug(" initDeploy() method started");
  initializeServices(getActivitiContext());
  deployBAR();
  LOG.logDebug(" initDeploy() method end");
}

public static void destroy() {

  ProcessEngines.destroy();
  LOG.logDebug(" Activiti Engine destroy() method end");

}

private static void initializeServices(
   ClassPathXmlApplicationContext context) {
  formService = (FormService) context.getBean(FORM_SERVICE);
  historyService = (HistoryService) context.getBean(HISTORY_SERVICE);
  identityService = (IdentityService) context.getBean(IDENTITY_SERVICE);
  managementService = (ManagementService) context
    .getBean(MANAGEMENT_SERVICE);
  repositoryService = (RepositoryService) context
    .getBean(REPOSITORY_SERVICE);
  runtimeService = (RuntimeService) context.getBean(RUNTIME_SERVICE);
  taskService = (TaskService) context.getBean(TASK_SERVICE);
}

public static ClassPathXmlApplicationContext getActivitiContext() {
  return new ClassPathXmlApplicationContext(ACTIVITI_CONFIG);
}

private static void deployBAR() {
  initDeploymentResource();
  getRepositoryService().createDeployment()
    .name(deploymentResourceInfo.getResourcename())
    .addZipInputStream(getBarStream()).deploy();
}

private static ZipInputStream getBarStream() {
  ZipInputStream barInputStream = null;
  try {
   barInputStream = FileUtil.getBarInputStream(deploymentResourceInfo
     .getResourcepath());
  } catch (FileNotFoundException e) {

   LOG.logFatal(new ActivitiException(ActivitiError.ERRORACVT001,
     "Deplyment file not found", e).getError(),e);
  }

  return barInputStream;

}

private static void initDeploymentResource() {

  BufferedReader fileReader = FileUtil.getResource(DEPLOYMENT_FILE);

  try {
   deploymentResourceInfo = FileUtil.getDeploymentInfo(fileReader);
  } catch (JAXBException e) {
   LOG.logFatal(new ActivitiException(ActivitiError.ERRORACVT002,
     "Internal Error", e).getError());
  }
}

public static void main(String acg[]) {
  UnifiedProcessEngine.initDeploy();
}

}

trademak
Star Contributor
Star Contributor
Hi,

Okay, please also include the bpmn20.xml so I can see how you have configured the async task.
Are you running this class with JMeter with 25 threads? Then you are actually starting 25 Activiti Engines right? Is that also your goal?
When the job executor is enabled this also means that 25 job executor threads are looking for jobs to process.
Therefore you receive an optimistic lock exception, because multiple threads want to claim the job, but only one succeeds.
So the optimistic lock exception is more an informational message in your test.

Best regards,

javatech
Champ in-the-making
Champ in-the-making
Basically Iam testing from brower.

see how i configured.


@WebListener
public class UnifiedProcessServer implements ServletContextListener {
public void contextInitialized(ServletContextEvent servletContextEvent) {
  initDeploy();
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
  destroy();
}
}

Web page looks like below.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Ticket created</title>
</head>
<iframe src="header.html" width="100%" height="20%"></iframe>
<body>

<%

java.util.Map<String, Object> prop = new java.util.HashMap<String, Object>();
prop.put("userReg", reg);

ProcessInstance processInstance = UnifiedProcessEngine.getRuntimeService()
  .startProcessInstanceByKey("ApprovalProcess", prop);

%>

<form action = "../demo/veiwdetails.jsp">
<input type="submit" value="Next" style="background-color:lightgreen">
</form>
</body>
</html>


Testing above jsp page url in Jmeter.
Process definition as below.

<process id="ApprovalProcess" name="approvalProcess">
       <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="ProjectRegiatration" name="ProjectRegiatration" activiti:class="com.cts.services.impl.MyDelegate"></serviceTask>
    <sequenceFlow id="flow3" name="" sourceRef="startevent1" targetRef="ProjectRegiatration"></sequenceFlow>
    <userTask id="usertask1" name="User Task" activiti:async="true" activiti:assignee="kermit"></userTask>
    <sequenceFlow id="flow4" name="" sourceRef="ProjectRegiatration" targetRef="usertask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow5" name="" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
  </process>



UnifiedProcessEngine.java as post before
pls let me know.
thxs

trademak
Star Contributor
Star Contributor
Hi,

Why did you make the user task async? The user task is async by default.
Please try again when you have removed this async attribute.

Best regards,

javatech
Champ in-the-making
Champ in-the-making
Great, Its working now for more than 50 Threads at a time.
Thx for your help.