Spring Singleton in Clustered Environment

為{幸葍}努か 提交于 2019-12-03 08:38:34

This is not necessarily the case.

It is a problem to use singletons across separate JVMs if they share meaningful state. For instance, a singleton that stored and issued incrementing IDs would be very dangerous if two separate instances existed on two separate application servers that were both part of the same application.

There is nothing inherent in Spring that makes this more or less tricky to deal with. Your Spring beans (likely services) should aim to maintain as little state as is practical as a matter of good practice. If they need to share state, then you will have to solve this problem just as you would with any other shared state.

A great many people use Spring in clustered environments and do not run into any problems relating to the above. I'm one of them!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!