Defering signals without getting Concurrent Modification Exception


Based on this post

if there is a situation where in I have multiple signals getting triggered and for a given state, only one of the signal is accepted and the other one is to be defered as it arrived too soon.
So in this case, if I use a ArrayDeque like structure to capture all the signals, based on the above post, I could defer the signal by removing it from the head and appended at last without getting any ConcurrentModificationException.

And also such scenario’s are also considered deterministic in nature ?

This scenario is deterministic as signals are recorded into workflow execution history and always replayed in the same order.

Note that ConcurrentModificationException is caused by changing a collection while it is being iterated. In your case, I would recommend using a Queue. It is safe to add and remove items from it in any order.

Here I am using Queue as suggested in earlier posts as well.

But in general, from concurrency point of view, based on the below code, there would not be anyway the ConcurrentModificationException would occur.

class WorkflowImpl {

   private List signals = new ArrayList();

   public void execute(){
       Wokflow.await((->{signals.size() > 0 });
       // logic to iterate on Signals list using for loop
       // and logic to remove() signal item from the list

   public void recvSignal(SignalInput input){


This is fine. But make sure that you don’t make any blocking calls after checking that signals size is 0.

Sure @maxim. Thank you for your support.