How to manage distributed transaction co-ordination between webservice calls and database?

StackOverflow https://stackoverflow.com/questions/15065951

سؤال

We have an external webservice which has exposed couple of APIs lock and unlock. The following are the steps followed while saving values in our system.

try 
  call lock
  save changes in single DB transaction
catch user_defined_exception
  call unlock

In case if there is any transaction timeout, we will not call unlock since this timeout exception is not considered to be part of user defined exceptions. Also in future, any new exceptions may be introduced , we dont want to include all those exceptions and do unlock.
We are looking for any industrial standard/pattern to do transaction co-ordination between service and database transactions.
Our application is built in java and the database is Sybase ASE. Any hints are greatly appreciated.

هل كانت مفيدة؟

المحلول

The recommended practice for correct locking with exceptions in Java is the following:

lock();
try {
  doStuff();
} finally {
  unlock();
}

This makes sure that the lock is released no matter what exception is thrown (or not), without the need to catch or re-throw it. However, this might still not be the safest thing to do in your case, since unlock() is a remote call and can itself throw exceptions.

The standard for coordination between services and databases is WS-AT. Any Java application server should support it, bridge with JTA, and with 2-phase commit on the database itself. When configuring the database connection in the application server, make sure you select the XADataSource option.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top