-
1. Re: Reloading stateless session beans programmatically in JB
kipflip Mar 11, 2005 5:03 AM (in response to gan_sub23)I'm not sure whether it works for Session Beans, but you could try something like the Sepuku Pattern which can be used to force reloads of Entity beans when using Commit Option A: if you throw a RuntimeException from your bean, the J2EE specification says the bean must be discarded. I guess (but haven't checked) that the same rule of discarding applies to Stateless Session Beans.
However, I'm not sure how you could ensure all beans in the pool were recycled this way. Perhaps you could have a timestamp field on your bean and use that to determine whether the instance needed to be removed. -
2. Re: Reloading stateless session beans programmatically in JB
jamesstrachan Mar 11, 2005 12:20 PM (in response to gan_sub23)There isn't a good way to reload stateless Session Beans, and there isn't meant to be.
Suggestions :-
a) Move the read only data from the Session Beans to a singleton Java class within the application Server. Reload data in the Singleton either when a timestamp expires or by touching the singleton from a servlet.
b) Do something very similar using an Entity Bean with a single, constant key to hold the read only data. Refresh using the same techniques.
You could use an Mbean to force reload in either alternative but a servlet will be quicker to develop and test.
Code for alternative (a)public class ReadOnlyCache { private ReadOnlyCache mySingleton; private HashMap properties; private ReadOnlyCache() {} public ReadOnlyCache getInstance() { if ( mySingleton == null ) { mySingleton = new ReadOnlyCache(); loadProperties(); } return mySingleton(); } public String getProperty( String key ) { return properties.get( key ); } public void refreshProperties() { loadProperties(); } private void loadProperties() { // Load the cached data from a properties file or whatever. } }
This example is deliberately simplified but shows a possible pattern to use. The servlet (code omitted) just gets the singleton instance and calls refreshProperties().
James