Reputation: 8151
I am working on an application which process the purchase orders.
This application is built on EJB1 and running on IBM Websphere.
I have a scenario/issue which need to addressed.
There's an Stateless Session Bean
which process bunch of orders (usually the number of orders is around 5K). I want to make this functionality synchronized.
i.e, If one of the users activate the order processing, no other users should be able initiate the process until the first processing complete.
due to some constraints I am unable to upgrade this to EJB3.
Are there any efficient ways to address this?
I am hoping the any provided solution require less code changes as well..
Upvotes: 0
Views: 202
Reputation: 1073
The answer really depends on where the orders exist/how they are stored, and how many concurrently running server instances might be able to initiate the order processing.
If the orders exist in memory only (seems unlikely) or there is only a single application server process running to perform this function, then you could just add a static field to your stateless session bean class and synchronize on it. This would provide functionality similar to an EJB 3.x singleton bean.
However, if this same application is running concurrently on multiple application server instances, then even a singleton bean wouldn't work for you, as there is still an instance per server, and thus no synchronization across processes. In this case, you really need to have the stateless bean obtain a lock of something where the orders are stored. For example, if your orders are stored in rows of a DB2 database, then you could add another table to that same database with just a single row, and the stateless bean would need to obtain a row lock of that row before it could process orders. This provides synchronization across processes (assuming all application server instances are accessing the same shared database).
Upvotes: 1