I need to maintain a simple counter, unique in the application, for all users and all nodes in a cluster environment. I was thinking about using the javax.ejb.Singleton annotation bean singleton session like this:
package foo; import javax.ejb.Singleton; @Singleton public class Bean { private int counter; [...] }
It looks simple, but I could not find the answer if it works as desired in a clustered environment. Each node in the cluster has its own instance or not?
Of course, I could save the bean in the database, but in reality it is only a counter, and that would be superfluous. In addition, I want the counter to be reset when the application crashes or is restarted, so saving it will create more problems than it solves.
source share