• Post Reply Bookmark Topic Watch Topic
  • New Topic

Concurrent Client Access to Entity Bean

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 concurrent remote java (non-j2ee, so I guess they dont have a transaction context to propagate to EJB) clients referencing the same Entity Bean in remote host. If they call the same remote interface method at the same time, would one client blocked waiting for the other to return? My method's transaction attribute is 'Required'.

If not, there would be a problem if the remote interface method is updating the CMP fields. One client's update would overwrite the other.

I have actually tried this out with J2EE SDK 1.3 but I can see the 2 calls executed concurrently in the EJB container (hence potentially overwriting each other's update)! I am not sure if this is a normal feature or just bug related to J2EE SDK 1.3 or because the client isnt calling with a transaction context.
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have actually tried this out with J2EE SDK 1.3 but I can see the 2 calls executed concurrently in the EJB container (hence potentially overwriting each other's update)! I am not sure if this is a normal feature or just bug related to J2EE SDK 1.3 or because the client isnt calling with a transaction context.


This depends on the isolation level. How it can be set is each Application server dependent.Some AS depends on the database being used.
 
Navin Pillu
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Damanjit

I agree that it depends upon the level of isolation. But what
specificaton says. According to specification what should be happened?
I don't hve much knowledge but what i think is that either it shouldn't
permit to access same data concurrently or it should reflect changes in
another instance also. I think it should not vary container-to-container
Plz explain the same. I'm also facing the same problem.

Thanks in Advance
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx for the info.

But can one entity bean instance (which represents 1 row in the db) to have its biz method called by 2 clients at the same time? i.e. 2nd client calls the method before 1st client's invocation of the same method return.

I am not totally convinced that this is dependent on the isolation level of the underlying database.

As I recall, we dont need to handle thread safety in entity bean and the container somehow ensure each entity bean accessed independent of other concurrent client. I dont understand how this is achieved but the logical deduction is that the container enforces serial access to each entity bean instance. But it seems that my testing of J2EE SDK 1.3 shows the container do allow >1 clients to call a method of a single instance at the same time!
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done some research and testing and it seems that the EJB container is pulling out 2 bean instances from the pool to service the 2 client calls - though there is only 1 EJBObject instance.

Am I right?
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set the isolation level to TRANSACTION_SERIALIZABLE, then I believe that this would effectively serialize requests to the bean. This will only work if both the database server and the EJB server support this isolation level.
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, one EJBObject at any time contains only one instance of a bean,
but for each client there is one instance separately in case of entity beans, so each instance will have its own values and the method call is on each separate instance for each client, but in database both instance can make changes that overwrite it each other changes during subsequent method calls on each instance. To control that - that all clients see same record values in database/or can see changes made by other method call - i.e. the concept of dirty, phantom reads etc are applied according to the database that is being used, I mean how the database itself handles it and Each Container has its own specifications as to how to specify this isolation level/ how it handles it, in case its not specified. There is always some default isolation level.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!