I am talking about classic enterprise applications. Typically hosted in some kind of application-server or container. Nothing fancy, just entities, services, Presentation/UI and relational storage.
Whenever I see the synchronized
keyword (either on methods or for blocks) in such an application I get very suspicious.
In my opinion this is either a sign for not understanding basic architectural concepts (for instance that a domain model is not shared between several clients) or even worse a sign that the architecture is actually very botched.
Do you share my mindset here? Or am I completely off track? Do you have use cases where synchronization is actually necessary in a classic enterprise application?
I agree with you for business logic code, but in an enterprise application you also have technical code and sometimes you need some synchronization for shared 'technical' state. The synchronized keyword may be used for this. (You also may relay on atomic variable, or use something outside your application like a DB sequence to share technical state...)
If you want to create sequential bill number - with no holes in the sequence - you need a way to share some state, and a way to synchronize...