cancel
Showing results for 
Search instead for 
Did you mean: 

java.util.ConcurrentModificationException

hardik_thakkar1
Champ in-the-making
Champ in-the-making
Hello,

I am getting below exception while running code from Web-app. Please help.

SEVERE: Servlet.service() for servlet appServlet threw exception
java.util.ConcurrentModificationException
   at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
   at java.util.HashMap$ValueIterator.next(HashMap.java:822)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:210)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:137)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:66)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
   at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
   at org.activiti.engine.impl.RepositoryServiceImpl.deploy(RepositoryServiceImpl.java:78)
   at org.activiti.engine.impl.repository.DeploymentBuilderImpl.deploy(DeploymentBuilderImpl.java:156)
   at com.rbos.marketrisk.controllers.TestActivitiController.executeWorkflow(TestActivitiController.java:48)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)

Code:

// Create Activiti process engine
      ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

      // Get Activiti services
      RepositoryService repositoryService = processEngine
            .getRepositoryService();
      RuntimeService runtimeService = processEngine.getRuntimeService();

      // Deploy the process definition
      repositoryService.createDeployment()
            .addClasspathResource("FinancialReportProcess.bpmn20.xml")
            .deploy();

      // Start a process instance
      String procId = runtimeService.startProcessInstanceByKey(
            "financialReport").getId();

      // Get the first task
      TaskService taskService = processEngine.getTaskService();
      List<Task> tasks = taskService.createTaskQuery()
            .taskCandidateGroup("accountancy").list();
      for (Task task : tasks) {
         System.out
               .println("Following task is available for accountancy group: "
                     + task.getName());

         // claim it
         taskService.claim(task.getId(), "fozzie");
      }

      // Verify Fozzie can now retrieve the task
      tasks = taskService.createTaskQuery().taskAssignee("fozzie").list();
      for (Task task : tasks) {
         System.out.println("Task for fozzie: " + task.getName());

         // Complete the task
         taskService.complete(task.getId());
      }

      System.out.println("Number of tasks for fozzie: "
            + taskService.createTaskQuery().taskAssignee("fozzie").count());

      // Retrieve and claim the second task
      tasks = taskService.createTaskQuery().taskCandidateGroup("management")
            .list();
      for (Task task : tasks) {
         System.out
               .println("Following task is available for accountancy group: "
                     + task.getName());
         taskService.claim(task.getId(), "kermit");
      }

      // Completing the second task ends the process
      for (Task task : tasks) {
         taskService.complete(task.getId());
      }

      // verify that the process is actually finished
      HistoryService historyService = processEngine.getHistoryService();
      HistoricProcessInstance historicProcessInstance = historyService
            .createHistoricProcessInstanceQuery().processInstanceId(procId)
            .singleResult();
      System.out.println("Process instance end time: "
            + historicProcessInstance.getEndTime());
6 REPLIES 6

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,
exception is connected to the deployment.
Could you create jUnit test for it?

http://www.jorambarrez.be/blog/2012/09/24/how-to-write-a-unit-test/

Regards
Martin

hardik_thakkar1
Champ in-the-making
Champ in-the-making
Thanks Martin.

I am not getting this exception every time. Sometimes it works fine.

What can be root cause of this? I can see it occurs while calling org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:210). Not sure how to overcome this issue.

I also tested this from standalone program, it's working fine. But getting issue while running it from container, Tomcat.

Any help much appreciated.

hardik_thakkar1
Champ in-the-making
Champ in-the-making
Adding more logs..

INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [activiti.cfg.xml]
INFO : org.activiti.engine.impl.ProcessEngineImpl - ProcessEngine default created
INFO : org.activiti.engine.impl.jobexecutor.JobExecutor - Starting up the JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor].
INFO : org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable - JobExecutor[org.activiti.engine.impl.jobexecutor.DefaultJobExecutor] starting to acquire jobs
Event received: ENGINE_CREATED
INFO : org.activiti.engine.impl.bpmn.deployer.BpmnDeployer - Processing resource FinancialReportProcess.bpmn20.xml
Event received: ENTITY_CREATED
Event received: ENTITY_INITIALIZED
Event received: ACTIVITY_STARTED
Event received: ACTIVITY_COMPLETED
Event received: SEQUENCEFLOW_TAKEN
Event received: ACTIVITY_STARTED
Event received: ENTITY_CREATED
Event received: ENTITY_INITIALIZED
Event received: ENTITY_CREATED
Event received: ENTITY_INITIALIZED
Event received: TASK_CREATED
30-Sep-2014 16:14:20 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet appServlet threw exception
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
at java.util.HashMap$ValueIterator.next(HashMap.java:822)
at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:210)
at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:137)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:66)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceByKey(RuntimeServiceImpl.java:69)
at com.rbos.marketrisk.service.impl.WFManagementServiceImpl.initiateWorkflow(WFManagementServiceImpl.java:18)
at com.rbos.marketrisk.controllers.WFManagementController.initiateWorkflow(WFManagementController.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

It seems that another thread has modified sessions map concurrently. (I think that I have read related topic on this forum already some time ago - try to search for it).

Regards
Martin

hardik_thakkar1
Champ in-the-making
Champ in-the-making
Thanks Martin.

While debugging Activiti code I found that there is one daemon thread which calls repeatedly and it flushes session by calling CommandContext. So It seems that this is the thing which is creating issue.

Shall I modify Activiti code for method flushSessions() by making it synchronized? Please suggest me possible workaround as it's road blocker for my project.

Just to give you idea about what we are trying to achieve, we are developing our own REST wrapper using activiti.jar which will be used by our clients. We are using Tomcat as container.

hardik_thakkar1
Champ in-the-making
Champ in-the-making
How can we make context reusable? I can see every time it tries to flush sessions. I want to flush them once context is destroyed. Is there any configuration for making context as reusable? Please suggest.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.