Hello, Does anyone know any articles or books considering Java/J2EE programming in clustered environment? I have many question in my mind but following is the most relevant. Is it possible to use ServiceLocator/Singleton as an cache in clustered environment? I should maintain a collection of data in a Singleton class read from database using an EJB. That data could be changed by a Web client in applications' program code. What I have understood is that Singleton classes instances are different in every Clustered node's Web container. So, if this is true, how can I synchronize data if it's changing in one of the clustered node/Web Container? Or is it possible to use EJB as an cache? Anyone had this kind of situation... Br Mik Laan
Singleton's aren't singletons in a clustered environment. Whether that matters or not depends on what you use them for. One use of a Singleton is to centralize access to some resources. The "singleness" is not critical, but is used to help with performance or memory or resource usage. It is OK to use this kind of singleton in a cluster, since having different instances on different machines is probably actually what you want, and doesn't affect the behavior. Another kind of singleton would be one that caches read-only data. Here you want to reduce the overhead of creating/querying/reading the data. You only want to do this expensive operation once, so you cache the data in a singleton. This kind of singleton is also OK in a cluster, since it still meets the expectations (reducing expensive data access). Another kind of singleton has some cache of read-write data. In this case, everybody that uses the singleton expects to get the correct current state. This kind of singleton, when implemented the traditional way using a static class variable, is bad in a cluster since each node of the cluster will have a different singleton instance, and they will get out of sync as soon as someone writes to it. But you can still implement a cluster-wide singleton as long as it is backed by something better than a static class variable, like a database. Probably the best fit for this would be an Entity Bean. The data is probably cached on each cluster node (depends on the app server), backed by a central database, and the app server may even keep the cluster node caches up to date with each other.
Joined: Sep 04, 2002
Thanks Dave! Can anyone suggest any books etc. that tell more about these kind of things in clustered programs. This is quite interested subject, Br Mik Laan