How singleton is javax.ejb.Singleton in a clustered environment?

后端 未结 3 1234
说谎
说谎 2020-12-31 19:42

I need to maintain a simple counter that is unique within the application, for all users and all nodes in a clustered environment. I thought about using the singleton sessio

相关标签:
3条回答
  • 2020-12-31 20:04

    Would every node of the cluster have it's own instance or not?

    Yes, each cluster node will have a different Singleton instance. Therefore, @Singleton annotation is not the solution for your problem.

    Take in mind that Java EE specification doesn't define any kind of cluster behavior. You need to search for specific vendor solution to achieve this kind of requirement. Just as an example see this link.

    0 讨论(0)
  • 2020-12-31 20:20

    You could use hazelcast . It's a distributed in-memory key-value store. Seems like it would be a perfect fit. It also implements JSR-107 which is the JCache spec.

    0 讨论(0)
  • 2020-12-31 20:23

    Ha singleton is an approach. As an advance, there are some limitations. If you read, you will have a @stateless bean that access to the service through a "getValue()" method. The get value calls a singleton bean's methods and gives to you a value... all right until there.

    But if you need to operate with the bean, a strategy should return a SingletonBean instance through get value, but.. you will have more instances of that singleton bean .... and there is the problem.

    0 讨论(0)
提交回复
热议问题