Adding Event Listener not Thread Safe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2014 07:44 AM
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)
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2014 02:24 PM
What's the use case for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2014 02:53 PM
At the moment we worked around it by registering a global listener and then registering our temporary listener to it. Our global listener is thread safe and makes sure this does not happen anymore (will be replaced with an Akka actor system in the future).
IMHO this is behavior that should be fixed in Activiti, as it can also happen during normal operations as well. E.g. when using a server wide Activiti engine that has several applications deployed using it.
Let me know your thoughts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2014 03:08 AM
Or is it only the collection of event listeners you want to make thread safe? Ie a simple synchronizedMap would suffice?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2014 04:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2014 08:50 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2016 10:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2016 04:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2016 04:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2016 03:29 AM
