I have a Spring based asynchronous method (annotated with @Async ) that I want to pause in case the error event occurs a certain number of times. Since there may be more than one thread doing the same, I tried the static AtomicInteger ( MY_COUNT ) so that all threads can know about the account and use the built-in concurrency AtomicInteger .
In my unit tests (run with SpringJUnit4ClassRunner in Eclipse) everything will be fine until the stream reaches MY_COUNT.incrementAndGet() . Then the stream simply disappears. No exception, nothing. Asynchronous workflow just disappears. I tried to take out AtomicInteger and just use synchronized methods, but the same thing happens.
Question: Is there any kind of interaction between @Async and synchronization? Is it impossible to combine the two?
EDIT: more info: it looks like this has something to do with the scope of synchronization (if that's the correct term). As soon as I removed the static notation from the counter variable, it still bombed; but then when I changed it to Integer and moved the increment code to my own synchronized method, then the code will continue. I did not debug the Spring base code; Are there any Spring experts who could shed light on this behavior?
source share