I've been trying to find out what (if any) consequences there may be for implementing
static class variables inside ejb3 stateless session beans. I've created some beans in
this manner and they appear to function as I would expect on a standalone JBoss server,
but I'm concerned that this technique may break clustering.
Essentially I'm trying to cache seldomly updated data (in the database) that is
requested very frequently on the web front end.
@Stateless
| public class CatalogBean implements Catalog
| {
| static boolean current = false;
| static String data = null;
|
| public void refresh()
| {
| current = false;
| }
|
| public String getData()
| {
| if(! current)
| {
| update();
| }
| return data;
| }
|
| private void update()
| {
| data = getDataFromTheDatabase();
| current = true;
| }
| }
Beans that are responsible for CRUD call the refresh method on this stateless bean - in
turn updating their shared cache. My (hazy) understanding is that the ejb container is
responsible to ensure that only one thread at a time can access a bean? Does this mean
that different instances can be accessed concurrently - and therefore I could have
syncronization issues? I suspect that static variables may be a bad idea - especially in a
clustered environment.
Perhaps there is a different or recomended approach that I have not considered? Thank you
in advance for all your comments and insights.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4028479#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...