Discussions

EJB design: Singleton for common properties in EJB environment

  1. Hello, We have an EJB application which is deployed in a Weblogic 9.2 clustered environment. There are certain properties like, url, cache time out, etc that we need to load from a properties file. We also have a requirement that to change these properties at RunTime, we are hoping to use JMX to update these values. Currently we have a Singleton class in our application which is instantiated at startup, which loads these properties. Also we have very stringent performance requirements, so getting values from this global properties repository must be very fast, less than a milli second. I found out that singletons are not a good idea in J2EE environment. So I was hoping someone would give me some other idea of implementing this Global properties issue we have. Thanks in advance
  2. You are facing two troubles with this approach: 1) you do not know how many class loaders you'll have and therefore your Singleton stops being single; 2) reading properties from a file is a common practice, but files become "unknown" data source for EJB Container. In WebSphere you even have to permit reading from files at deployment time, it's treated as mistake. Why wouldn't you try using simple stateless session bean with local interface and configuration read directly from deployment descriptor? It should even ease updating the properties.
  3. A simple solution, I would suggest is to keep the properties in database, use a entity bean to retrieve the data. the container will handle the replication and caching issues and data integrity. And in your case, updating the data also becomes easy. And regarding the performance, may be only for the first time it would be slow, rest of the time, when the entity bean is already loaded into memory, it will be fast. Use local home to invoke the ejb from your web layer (assuming both web and ejb are on the same app server).
  4. Hi Viktor, David, Thank you for your input. I think I will try out the Database and Entity bean with Container Managed Persistance to test this. thank you, Jacob.