Using arbitrary resources with JTA

荒凉一梦 提交于 2020-01-12 09:53:11

问题


Is it possible to make any type of custom resource transactioal with JTA? Let's assume a basic example and take a Folder creation that should be rolled back in case of an error.

Can such custom resources be handled?


回答1:


Yes. That resource needs to provide an implementation of XAResource, and an instance of that implementation needs to be enlisted with the transaction when the resource is used. The resource can get the current transaction from the transaction manager in order to carry out the registration when it is accessed (i think).

You could look at the code to XADisk, which is apparently an XA-transactional file manager, to see how it's done there.

However, a common approach to doing this in the J2EE world is not to deal with JTA directly, but to write a resource adapter using JCA, which lets the J2EE container handle not only transactions, but pooling, naming, and various other enterprisey details. However, the JCA API is not exactly straightforward, and as difficult as it is, it is defended by a mountain of even more difficult documentation, whose main purpose seems to be to prevent understanding of it!



来源:https://stackoverflow.com/questions/6736241/using-arbitrary-resources-with-jta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!