java.util.ConcurrentModificationException in shouldWorkWithCreateActionTriggers
Although the execution has finished by executeBlocking
, the collector sink still receive further elements.
I guess the dynamically created threads are still alive.
So far, the execution is not aware of dynamic threads.
Solution A: Add the dynamically created threads to the finite producer or consumer list.
Problem with this solution:
When waiting for termination, the execution enters the finite producer list.
If a threads is added to this list at runtime a ConcurrentModificationException
can occur.
Solution B: Add another list of threads that represents all dynamically created threads. Wait for it after the finite producers and consumers.
Problem with this solution: The execution could have finished before
Solution C:
Add a thread-safe counter that tracks the current number of running threads.
The execution waits for it to become 0, i.e., all threads have been finished.
Remove waiting with Thread.join
calls.
Not appropriate for this use case:
-
CountDownLatch
: Cannot increase counter. -
ReentrantLock
: Too much write effort. -
Semaphore
: All threads would block if the semaphore is non-positive. -
CyclicBarrier
: All threads wait for each other after proceeding. Not our use case. -
Phaser
: API is too complicated (not just inc, dec, and await as expected)