0

In spring integration application, I am using concurrent consumers to consume and process the multiple messages at a time. In my application, I configured all beans to a singleton. I am assuming if I am going to parallelize the processing by using the concurrent consumer's, multiple messages entered into same integration components. Does it leads to data collision between two objects?

Jai
  • 13
  • 3

1 Answers1

0

Does it leads to data collision between two objects?

No, that doesn't mean. If you don't do any state management in your components, then the is not going to be any collisions. Just because one thread can perform only one task at a time. So, if you use the same component in different threads to perform stateless work, there is no any inter-thread interaction. Just because each thread get its own call stack.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • In other words, you must not have any shared state (fields) in your beans; they must be stateless, or the state protected with locks. It's generally better to keep everything stateless. – Gary Russell Feb 26 '18 at 15:10
  • Do you modify (mutate) some properties in those singletons? I think you need to come back to the Java Concurrency per se – Artem Bilan Feb 26 '18 at 16:57
  • If I configured bean state to prototype does it slove the problem? Can you please suggest the best practice to create the bean type in spring integration. – Jai Feb 26 '18 at 17:00
  • No, you're doing well. You just don't understand what does `stateless` means and we are speaking here on different languages. So, if your singleton has `foo` property and during `process()` method call you save a value to that `foo`, then it isn't `stateless` and your component is not thread-safe. That's all. Please, read more about Java Concurrency. There is nothing specific in Spring Integration. It's still the same Java – Artem Bilan Feb 26 '18 at 17:02