We have written one Stateless Session Bean. It has two methods. Method A and B.
Inside this method, I call a method on the helper class, which creates a static Hastable object. I store some value in this static object.
Inside this method also, I call a method on the same helper class I used for Method: A and reading the value from the static Hashtable object which got stored by Method A.
This is working fine for a single application server. If we go for Server Clustering, will it create any problem? How the value got changed in static object on one cluster member server will be replicated in the other member server? Whether it is possible or not?
Please give your suggestions. Thank you in advance.
When you go to a cluster, your stateless session beans won't be replicated, they are just available on all of the servers. Each server will have its own instance of your Hashtable and they will be different.
WebLogic doesn't have the concept of once-only objects in memory across the cluster right now. The only way to get it is to store stuff in a single database and then access the database from all servers.
Thank you for the information. I just write the exact requirement here.
In our application we need to generate some auto-generated numbers which will be the primary key in the database tables. We can go for sequences in oracle database. But, our application is database independent. So, what we think is we can cache a number in the app server and for every insertion in the database we will increase this number by one and insert into the table with other details. For primary key we will always take from the cache which is available in the app server.
The alternate solution could be having some table in the database and store the sequence value in that table. For every insertion, we can read the sequence from this table and increment this sequence value by one. But, many times we have to access the database in order to get the sequence. We fear of dead lock also with this solution since the transactions are very big. That is the reason we thought of the above solution.
But in the caching solution, as you pointed out, it will create problem while clustering of app servers. Could you please give a solution by which we should avoid of going to database frequently and clustering of app server also should not create problem.
Presently, stateless session bean method requires such auto generation of sequence number.
Expecting your help. Thank you in advance.
FYI... WLS 6.1 supports automatic primary key sequencing. It does what you need it to do for CMP entity EJBs.
There is a pattern that covers your exact requirement.
Have a look at the 'high-low' pattern on this site. It uses a stateless session bean and a singleton to generate the primary-keys.
There are also a number of related patterns.
BTW, ECPerf (http://java.sun.com/j2ee/ecperf
) also uses the pattern (with 'cheating' stateless session bean) for pk generation.
and have u deployed ECperf on WL6.0?
pls if you have success help me with some explanations ?
Thank you a lot for good suggestions.
I saw the pattern "high-low" on this site. It looks like, this pattern won't be solving my problem 100%.
Some more requirements on Primary Key generation are:
Let us assume that the table "CUSTOMER" needs auto-generation of Primary key for the field "CUST_CODE". In our application we have to display CUST_CODE also to the user. But it is an auto-generated one and can be run like this.
CUST000001, CUST000002, CUST000003......... like this.
ORDER_CODE on "ORDER" table can run like this:
ORDER00001-dd/mm/yy, ORDER00002-dd/mm/yy, ..... like this.
(here dd/mm/yy are always today's date)
There are two types of user in our system. Normal user and Administrator. For Normal user auto generation should happen as per the format already mentioned. If the user makes an order then the ORDER_CODE should be generated in a sequence of format ORDER000001-dd/mm/yy.
But, administrator can make a change in the format of the sequence to be generated.
If one application server is there, then we can store the format in a SingleTon object and we can keep on generating the sequence. Even though the administrator makes the change, we can make a change in the SingleTon object and store the format in the database also. The SingleTon object can be loaded with this format while starting the server. There is absolutely no problem if there is only one app server.
The problem arises when we go for Clustering of app servers. Solutions are available for Primary key generation by keeping in mind, they are unique numbers only and will not be shown to the user. But, if we want them to be customizable also, how to go about it? Going to database for each request is the only solution? Please help me.
One thing to keep in mind in Weblgic 6.0 you can use the JNDI tree to hang values off of, and this is replicated in the cluster. So if you want to hang an increment value, you can create a session bean that pulls the value off of the JNDI tree increments it and puts it back, this way you don't have to use the database to do that. You can use the High/Low pattern in a start up class and hook the low part to the JNDI tree, this will then replicate across your cluster.
Could you please give some more information with reference to the implementation point of view?