120 Transaction management catch (JDOException je) { //
120 Transaction management catch (JDOException je) { // transaction rolled back advise the user or take // other appropriate action } } Long-lived transactions typically occur when transaction demarcation is dependent upon intervening user activity. An example would be a transaction that is held open whilst a user enters data. In such cases the use of pessimistic transactions may cause excessive locking to occur in the data store, thereby reducing the overall concurrency of the system. Although pessimistic transactions can be used in such cases, optimistic transactions provide an extremely useful alternative. 7.3.2 Optimistic transactions When working with long-lived transactions, it is often unacceptable to physically lock data in the data store for the duration. Optimistic transactions stem from an approach to increase concurrency (reduce locking) in such instances. The basis for doing this is a set of optimistic concurrency assumptions; it is presumed that any data altered in the optimistic transaction will not actually be altered by any other transaction until the first has been committed. Since in many cases this assumption is indeed true 99% or more of the time, there is no need to physically lock the underlying data. The only thing that needs to be done is to verify that the assumptions are indeed true before our changes are actually written to the data store. A typical optimistic transaction under which a BusinessPartner is to be changed, and which is executed against a database that does not provide native support for optimistic transactions, would have the following steps (for those data stores which do support optimistic transactions, these steps would conceptually still apply but the implementation would be much simpler): 1 Read the business partner from the data store and obtain some piece of information by which we can later tell whether this object has had changes committed to the data store; this typically involves a timestamp or an object version number. Where the database schema has been previously dictated it may not be possible for such version number or timestamp information to be added to the tables. In these cases the entire state of the data store entity may be used for comparative purposes. (Where the data store natively supports optimistic transactions there will be no need for this additional information.) 2 Allow the business partner to be updated. These updates may occur over a period of time, during which the corresponding data store entity is not locked. 3 When the transaction is finally committed, a short-lived pessimistic transaction is started on the underlying data store. The data store is checked to determine
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check Actions servlet hosting services