This content has been marked as final.
Show 1 reply
-
1. Re: global config file design pattern
jamesstrachan Feb 19, 2005 9:15 AM (in response to kevliang)kevliang,
I think that everything you suggest will work, except that I don't know whether you can register an mbean with JNDI.
I have found it possible to use an entity bean as a singleton by defining a single constant value as the primary key. The constant value is defined somewhere in the package :-public static String CACHE_SINGLETON_KEY = "CacheControl";
and then all other EJB and web applications can reference the singleton and access data through business methods.
This works well and fits the J2EE model architecture. It strongly implies that your cached data is loaded from a database.
The ejbLoad() method may be called before each business method is executed. It is probably advisable to use BMP and to reduce the number of database reads as shown below :-public void ejbLoad() { if ( System.currentTimeMillis() > cacheExpiryTime ) { doRealLoad(); cacheExpiryTime += RELOAD_INTERVAL; } }
where the private method doRealLoad() performs the actual work, and the constant RELOAD_INTERVAL is used to determine the interval between loads.
Hope this helps.
James