EJB by default prohibits cuncurrent access to bean instances.In other words several cleints can be connected to one EJB Object but only one client thraed can access the bean instance at a time.
But suppose I have one EJB Object A another B both is allocated a entity bean instance to service the client calls and both these instances represents the same underlining database row.
Can any body say Then how does EJB implements cocurrency ? Because now as far as I think two clients can very well access the same data at the same time.
Please correct me If I an wrong at any point of time.
I'm not sure I understand your confusion. All requests to an EJB Object is routed to the application server's EJB container. The container makes sure that only one thread is calling the EJB at a time. Each EJB has a primary key, the container will make sure that only one EJB Object is allocated at a given time for a specific primary key. These rules work slightly differently in a clustered environment. You will have to consult the application server vendor's documentation for the details in this case.
Please note that for performance reasons you can use value objects (or flyweight objects). This design pattern sends the entire database row(s) for a logic entity to the client as a serializalbe java object. This design pattern would allow many clients to get the same database row(s) (in the form of the value object) at the same time. Look for the ejb design patterns for the details.
How concurrency works is very vendor specific.
For instance WL standard configuration is database concurrency where the container will allocate a different Entity Bean regardless of the PK. This relies on the database to sort out any locking/synchronizing issues. This was a performance optimization from 6.1 onwards.
You can set the concurreny level to Exclusive where the container will only allocate one Entity Bean instance for each PK and will syncronize access. This was the default for 5.1.
All requests to an EJB Object is routed to the application server's EJB container. The container makes sure that only one thread is calling the EJB at a time. Each EJB has a primary key, the container will make sure that only one EJB Object is allocated at a given time for a specific primary key.
The EJB specification generally gives the application server a lot of freedom as to what type of concurrency control it would implement. I think what you are describing is known as commit option A (although I think some of your terms are comfused). There are also standard commit options B and C which instanciate multiple entity bean instances to handle multiple clients accessing the same entity. There can also be concurrency control methods other than commit options A, B and C. The EJB spec does not dictate a concurrency control mechanism.
To answer Sabyasachi's question, there are generally two common options:
1. Commit option A is used, only one client accesses an entity at a time.
2. Commit option B or C are used, database transactions are used to resolve concurrent access conflicts. In this case some servers will allow you to configure the transaction isolation level and other settings to achieve the level of concurrency control you need.