-
1. Singleton in clustered JBoss AS 6 Final
ilya40umov Jan 25, 2011 10:06 AM (in response to danosterrath)I guess you can try this:
As all the data in a singleton should be the same in all nodes. You can just use some flag inside you singleton and if this flag shows that action has been already executed today you can simply skip it on the other nodes.
Does it work for you?
-
2. Re: Singleton in clustered JBoss AS 6 Final
danosterrath Jan 25, 2011 10:35 AM (in response to ilya40umov)Well, the flag had to be set before executing the action. Unfortunatelly checking and setting the flag can not be atomic over all nodes. So this might lead to a race condition that multiple instances enter the "synchronized" area. (Which in fact is not synchronized.)
if (flag) { // <--- here the race condition might occur flag = true; doSomeLongRunningTasksInDB(); flag = false; }
-
3. Re: Singleton in clustered JBoss AS 6 Final
ilya40umov Jan 25, 2011 10:44 AM (in response to danosterrath)Managing Concurrent Access in a Singleton Session Bean
Singleton session beans are designed for concurrent access, situations in which many clients need to access a single instance of a session bean at the same time. A singleton’s client needs only a reference to a singleton in order to invoke any business methods exposed by the singleton and doesn’t need to worry about any other clients that may be simultaneously invoking business methods on the same singleton.
When creating a singleton session bean, concurrent access to the singleton’s business methods can be controlled in two ways: container-managed concurrency and bean-managed concurrency.
The javax.ejb.ConcurrencyManagement annotation is used to specify container-managed or bean-managed concurrency for the singleton. With @ConcurrencyManagement, a type attribute must be set to eitherjavax.ejb.ConcurrencyManagementType.CONTAINER or javax.ejb.ConcurrencyManagementType.BEAN. If no @ConcurrencyManagement annotation is present on the singleton implementation class, the EJB container default of container-managed concurrency is used.
Take a look at this link for the details:
-
4. Re: Singleton in clustered JBoss AS 6 Final
rhanus Jan 26, 2011 7:28 AM (in response to danosterrath)the combination of both
@Singleton and
@Clustered
doesn't make up a clustered singleton beanyou need to set up a singleton service here is some backround for jboss-5.x should work in 6.0 as well
the simplest way is to package bean above into a separate archive and deploy it into deploy-hasingleton or use HASingletonControler and implement custom jboss service
-
5. Re: Singleton in clustered JBoss AS 6 Final
wolfc Jan 26, 2011 7:51 AM (in response to rhanus)Keep in mind that state is not replicated across the cluster using these methods. Also to enable scaling there should really be a singleton instance available on each node.
I've created EJBTHREE-2234 as a placeholder for future reference.