cancel
Showing results for 
Search instead for 
Did you mean: 

Reuse of Java delegate class fails

pekour
Champ in-the-making
Champ in-the-making
Hello everyone.

I'm Activiti of version 5.16.3.0 on Tomcat 7.0.32 and Java 1.7.0_09. Generally i need to use the loop which will contain Java Delegate task, but I encountered the problem with delegate class instantiating. After variable number of iterations the task fails with the stack trace in the ACT_GE_BYTEARRAY which says that delegate class can not be found.

I prepared the simplified case which 100% guarantees the failure on the second java task. Here it is:

The delegate

package com.dummy;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;

public class DummyDelegate implements JavaDelegate {

  @Override
  public void execute(DelegateExecution arg0) throws Exception {
    System.out.println("—————— Hello, i'm the dummy delegate!———————-");

  }

}


The process. I contains two java delegate tasks, divided by usertask with timer bounday, which, i believe, separates the threads of execution.


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="dummy">
  <process id="test_two_delegates" name="test_two_delegates" isExecutable="true">
    <startEvent id="startevent" name="Start" activiti:initiator="initiator"></startEvent>

    <sequenceFlow id="flow1" sourceRef="startevent" targetRef="servicetask1"></sequenceFlow>

    <serviceTask id="servicetask1" name="Service Task" activiti:class="com.dummy.DummyDelegate"></serviceTask>

    <sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="usertask1"></sequenceFlow>

    <userTask id="usertask1" name="User Task"></userTask>
    <boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="usertask1" cancelActivity="true">
      <timerEventDefinition>
        <timeDuration>PT10S</timeDuration>
      </timerEventDefinition>
    </boundaryEvent>

    <sequenceFlow id="flow3" sourceRef="boundarytimer1" targetRef="servicetask2"></sequenceFlow>
    <sequenceFlow id="flow5" sourceRef="usertask1" targetRef="servicetask2"></sequenceFlow>

    <serviceTask id="servicetask2" name="Service Task" activiti:class="com.dummy.DummyDelegate"></serviceTask>

    <sequenceFlow id="flow4" sourceRef="servicetask2" targetRef="endevent"></sequenceFlow>

    <endEvent id="endevent" name="End"></endEvent>
  </process>
</definitions>


And the stacktrace is the following:

org.activiti.engine.ActivitiException: couldn't instantiate class com.dummy.DummyDelegate
   at org.activiti.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:132)
   at org.activiti.engine.impl.bpmn.helper.ClassDelegate.instantiateDelegate(ClassDelegate.java:192)
   at org.activiti.engine.impl.bpmn.helper.ClassDelegate.getActivityBehaviorInstance(ClassDelegate.java:165)
   at org.activiti.engine.impl.bpmn.helper.ClassDelegate.execute(ClassDelegate.java:114)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:80)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:116)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:35)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:114)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:35)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:440)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.takeAll(ExecutionEntity.java:537)
   at org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior.execute(BoundaryEventActivityBehavior.java:63)
   at org.activiti.engine.impl.jobexecutor.TimerExecuteNestedActivityJobHandler.execute(TimerExecuteNestedActivityJobHandler.java:56)
   at org.activiti.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:83)
   at org.activiti.engine.impl.persistence.entity.TimerEntity.execute(TimerEntity.java:67)
   at org.activiti.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:73)
   at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
   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.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:52)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:745)
Caused by: org.activiti.engine.ActivitiClassLoadingException: Class not found: com.dummy.DummyDelegate
   at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:82)
   at org.activiti.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:129)
   … 73 more
Caused by: java.lang.ClassNotFoundException: com.dummy.DummyDelegate
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Class.java:270)
   at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:63)
   … 74 more



How can I configure Activiti to make this case working?
7 REPLIES 7

pekour
Champ in-the-making
Champ in-the-making
Upgrade to Tomcat 7.0.57 and Java 1.7.0_71 unfortunately made no any effect

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,


Caused by: java.lang.ClassNotFoundException: com.dummy.DummyDelegate
Is com.dummy.DummyDelegate class in the classpath?

Regards
Martin

pekour
Champ in-the-making
Champ in-the-making
Of course. I may be missed to emphasize that it works for the first occurence of the java task and the error triggers only for the second one.

martin_grofcik
Confirmed Champ
Confirmed Champ
Can you create jUnit test for it (to be able to reproduce the issue easily)
http://forums.activiti.org/content/sticky-how-write-unit-test

Regards
Martin

pekour
Champ in-the-making
Champ in-the-making
Hello again. I've attached the testcase with txt extention since zips are not allowed here. The testcase shows that the process is still stuck after 15 seconds and the second execution of the delegate doesn't happen, but i'm not sure how to take a look into the H2 database in order to get the stacktrace from the ACT_GE_BYTEARRAY.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

add

    <property name="jobExecutorActivate" value="true"/>

to activiti.cfg.xml file. JobExecutor is not activated by default. Another possibility is to use org.activiti.engine.impl.test.AbstractActivitiTestCase#waitForJobExecutorToProcessAllJobs.

Regards
Martin

pekour
Champ in-the-making
Champ in-the-making
Thank you for the idea.
I think that i finally found the reason of the failure: i had several activiti installations connected to the same db and their shared the execution of the loop while having differend codebase because in 5.16.3 jobExecutorActivate is true by default in activiti-explorer.war.