What EJB version do you use 2.x or 3.x? It will help for an answer.
Best try is to avoid such 'stateful' behaviour ;-(
For our application (do not use spring) we found out that it will work without some caching more stable and without a performance drawback.
We have entities with a high change frequency and the data in cache are ruled out and must be loaded anyhow.
Solutions for you might be
- JBoss(Tree)Cache, replicate the state in the cluster (time gap possible because of async replication after commit)
- Special entity without caching or with the invalidation feature (EJB2 entities)
- your own implementation and a signal if it must be refreshed (we do this for master data via JMS)
Also you should think about the load-balancing, it is not ensured that two calls of SLSB in a sequence will reach the same JBoss instance in a cluster, this might produce problems if the cache-data will be not the same ...
I'm really sorry, I forgot to say that we're using EJB3 and annotations.
Our cluster will be load balanced, and one of the problems related to this sort of things is what you mentioned.
About your solutions I must say that about the cache we're thinking about it and there's another open discussion on this forum for another problem we're having;
The second one has been also considered but we're keeping it as last resort.
Thanks a lot
With EJB3 entities there is only a transactional caching (no 2nd level cache like EJB2).
Are you sure that the caching will spare significant duration or cpu time ?
A good principle will be 'only think about cache if you measure that it will bring benefit'
Without going deep in details, the field (an hashmap) of the stateless ejb contains data fetched from rss, forecasts and other data taken from internet that are loaded once a day.
Clients can't connect directly to internet, and this kind of data is not storable into the application database.
Loading and collecting information from these sources would be very intensive if we didn't cache in some way; that's the reason for this cache.
I understand the reason for the cache (was just food for thought)
But another one ...
If this data is loaded only once a day it might aceptable to load local on each cluster node at the same time,
because if the time is in sync the difference is only a few seconds ...
Yes, probably we could in some way.
Googling we found this link, maybe a bit old but we would like to give it a chance anyway:
So now we're thinking about having our "cache" in a hasingleton, every ejb pointing to it, and when a node goes down, the shared state will grant that no data is lost.
What do you think?
Also a solution.
AFAIK the HA-singleton will start only once in a cluster (like JMS JBossMQ). In case of node crash there will be a gap al long as one other instance provide the service.
Just to tell you how the developers decided to solve this "issue".
Basically, the injected singleton became a service, so singleton on every node, with a dependency to the HASingletonDeployer, just like the following:
In this way the bean will be deployed just once for all the cluster instances.
From now on, for referencing your bean, you can use the Depends annotation on the field:
private MyService myService;
In our scenario, since the data are loaded once in a day and put into the cache, we're fine even if we experience same gap before the service starts again on another node.
I have tried your solution its works for the first node of my jboss 5.1 cluster, but when i start my 2nd node it does not deploy my ear and throws following error:--
DEPLOYMENTS MISSING DEPENDENCIES:
Deployment "jboss.j2ee:ear=vtp.ear,jar=vtpEnterpriseBeans.jar,name=JobService,service=EJB3" is missing the following dependencies:
Dependency "<UNKNOWN jboss.j2ee:ear=vtp.ear,jar=vtpEnterpriseBeans.jar,name=JobService,service=EJB3>" (should be in state "Described", but is actually in st
ate "** UNRESOLVED Demands 'jboss.ha:service=HASingletonDeployer,type=Barrier' **")
Deployment "jboss.j2ee:ear=vtp.ear,jar=vtpEnterpriseBeans.jar,name=JobService,service=EJB3_endpoint" is missing the following dependencies:
Dependency "jboss.j2ee:ear=vtp.ear,jar=vtpEnterpriseBeans.jar,name=JobService,service=EJB3" (should be in state "Configured", but is actually in state "PreI
DEPLOYMENTS IN ERROR:
Deployment "<UNKNOWN jboss.j2ee:ear=vtp.ear,jar=vtpEnterpriseBeans.jar,name=JobService,service=EJB3>" is in error due to the following reason(s): ** UNRESOLVE
D Demands 'jboss.ha:service=HASingletonDeployer,type=Barrier' **
can u please help with this?
I suspect this is related to an issue already registered in Jira (https://issues.jboss.org/browse/JBAS-7096).
Anyway, that looks like the one I got, but the whole thing works fine once you stop the active node. After that, you should see in the log of the new active node the registration of the ejb.
Please let me know
Message was edited by: Alessandro Novarini, added link to Jira issue