AnsweredAssumed Answered

Adding Event Listener not Thread Safe

Question asked by elmarweber on Nov 10, 2014
Latest reply on Jun 3, 2016 by jbarrez
Hello,

when adding a event listener during runtime I get (in unit tests) a ConcurrentModificationException because at the same time I add the listener an event is dispatched (see exception below).

The error occurs here, while dispatching an event through the listeners the eventListeners array is modified.

[java]
         for (ActivitiEventListener listener : eventListeners) {
            dispatchEvent(event, listener);
         }
[/java]

Is this a bug or intended behavior, e.g. it is not intended to add an event listener during operations?

Activiti 5.16.4

Thank you,
Elmar


[error]    ConcurrentModificationException:   (ActivitiEventSupport.java:89)
[error] org.activiti.engine.delegate.event.impl.ActivitiEventSupport.dispatchEvent(ActivitiEventSupport.java:89)
[error] org.activiti.engine.delegate.event.impl.ActivitiEventDispatcherImpl.dispatchEvent(ActivitiEventDispatcherImpl.java:65)
[error] org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:74)
[error] org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
[error] org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
[error] org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)
[error] org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:116)
[error] org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)
[error] org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:621)
[error] org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:616)

Outcomes