Originally posted by William Silva:
For example :
Client 1 call the method setName("Client1");
Client 2 call the method setName("Client2");
How will be the name after the transactions end ?
Actually, to make this clearer it helps to have a slightly more complex example:
Client 1: call setName("Client1"), setValue(1)
Client 2: call setName("Client2"), setValue(2)
If the two method invocations by each client are wrapped in a transaction then you are guaranteed that the resulting (name,value) state will either be ("Client1",1) or ("Client2",2), but not a mish-mash. Which you get will depend on the order in which the client transactions were initiated (the second transaction would block until the first had completed as soon as the transaction tried to access a resource already required by the first transaction).
Sometimes it is easy to psych yourself into thinking that something bad is happening when two clients are working at more-or-less the same time, but as long as the results are consistent (not a mish-mash), then it really isn't any different than the situation when the client activities are days apart. The first client changed the state. The second client changed the state. The final result is determined by who went last.
Where things get a bit wierd is when you are changing state based on stale information (e.g. read an entity bean, stuff data in a web page, customer submits a change, use entity bean to save change). The wierdness comes from the fact that you don't have a single transaction. You don't get this problem when a session bean reads and writes an entity bean in the same transaction, because the entity bean has a lock on the row in the database until the transaction is committed.