cancel
Showing results for 
Search instead for 
Did you mean: 

problem with 'custom timer task'

djanca
Champ in-the-making
Champ in-the-making
Hi all,
I have to write something like timer task, that periodically checks a database for a value (e.g. timestamp) and when this value passes some condition, our process flow shall proceed. I have to create special custom task for it, not to design it as a process loop.

my task class:
public final class CustomTimerTask implements SignallableActivityBehavior, Serializable {
 
    @Override
    public void execute(ActivityExecution execution) throws Exception {
        signal(execution, null, null);
    }

    @Override
    public void signal(ActivityExecution execution, String signalEvent, Object signalData) throws Exception {
        if (evaluateTimer(execution)) {
            leaveTask(execution);
        } else {
            scheduleNextTimer(execution);
        }
    }

    private void scheduleNextTimer(ActivityExecution ae) {
        TimerEntity timer = new TimerEntity();
        timer.setRepeat(null);
        timer.setJobHandlerType(TimerCatchIntermediateEventJobHandler.TYPE);
        timer.setJobHandlerConfiguration(ae.getActivity().getId());
        DateTime dueDate = new DateTime().plusMinutes(getPeriod(ae));
        timer.setDuedate(dueDate.toDate());
        timer.setExecution((ExecutionEntity) ae);

        Context.getCommandContext().getJobManager().schedule(timer);
    }

  private boolean evaluateTimer(ActivityExecution ae) {
        … some logic
    }
}

first execution passes correctly and new job is scheduled for execution. but my problem comes with next (sometimes 3rd - really!) scheduled execution.
the activiti scheduler logic throws ClassNotFoundException - cannot instantiate my timer task implementation.

Stacktrace:
org.activiti.engine.ActivitiException: couldn't instantiate class de.workflow.task.TestTimerTask
   at org.activiti.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:131)
   at org.activiti.engine.impl.bpmn.helper.ClassDelegate.instantiateDelegate(ClassDelegate.java:156)
   at org.activiti.engine.impl.bpmn.helper.ClassDelegate.getActivityBehaviorInstance(ClassDelegate.java:129)
   at org.activiti.engine.impl.bpmn.helper.ClassDelegate.signal(ClassDelegate.java:118)
   at org.activiti.engine.impl.jobexecutor.TimerCatchIntermediateEventJobHandler.execute(TimerCatchIntermediateEventJobHandler.java:43)
   at org.activiti.engine.impl.persistence.entity.JobEntity.execute(JobEntity.java:78)
   at org.activiti.engine.impl.persistence.entity.TimerEntity.execute(TimerEntity.java:62)
   at org.activiti.engine.impl.cmd.ExecuteJobsCmd.execute(ExecuteJobsCmd.java:61)
   at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
   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.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:36)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
   at java.lang.Thread.run(Thread.java:619)
Caused by: org.activiti.engine.ActivitiClassLoadingException: Class not found: de.workflow.task.TestTimerTask
   at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:81)
   at org.activiti.engine.impl.util.ReflectUtil.instantiate(ReflectUtil.java:128)
   … 17 more
Caused by: java.lang.ClassNotFoundException: de.workflow.task.TestTimerTask
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1576)
   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Class.java:247)
   at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:62)
   … 18 more

we are using activiti 5.8 and we have an enterprice application built into EAR file, activiti jars are in EAR/lib directory and custom task implementation is in EAR/<war-file>/WEB-INF/classes (but I also tried to packed my class directly into activiti.jar).

thanx for any hint. I'm running out of ideas.
1 REPLY 1

djanca
Champ in-the-making
Champ in-the-making
solved

the problem was caused by the fact, that multiple activiti engines ran against the same database and all of them had enabled jobExecutor. the class in question existed only in my local development environment.
silly problem  :lol: