Welcome to CodeRanch!
Michael Straub wrote:TL;DR: If singleton beans in Spring's context are not threadsafe, how do we manage multiple requests/threads accessing the service bean and not creating inconsistency?
Singleton beans MUST be thread-safe, in every case.
But my confusion is that the singleton bean(CommentService) that is creating the prototype beans(CommentProcessor) is not thread safe either.
Why? What makes you think that
CommentService is not thread-safe?
So to make it thread safe we will have to synchronize sendComment()? Would not this effect performance?
You must NEVER synchronize on singleton beans. To make them thread-safe, they must be stateless. You do this by making them immutable.
The
CommentService class is immutable, and therefore thread-safe.