如何将数据附加到JTA交易? (或唯一标识) [英] How can i attach data to a JTA transaction? (or uniquely identify it)

查看:82
本文介绍了如何将数据附加到JTA交易? (或唯一标识)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个getStockQuote()函数,该函数将从股市中获取交易品种的当前股票报价.

I have a getStockQuote() function that will get a current stock quote for a symbol from the stock market.

我的目标是在JTA交易中,对getStockQuote()的首次调用将获取股票报价,但是同一事务中的所有后续调用将重用相同的股票报价(例如:它将不会尝试获取新的股票报价)引用).如果开始另一笔交易,或同时执行另一笔交易,我希望另一笔交易在其第一次调用时取回其自己的股票报价.

My goal is that within a JTA transaction, the first call to getStockQuote() will fetch a stock quote, but all subsequent calls within the same transaction will reuse the same stock quote (e.g.: it will not try to fetch a new quote). If a different transaction starts, or another transaction runs concurrently, i would expect the other transaction to fetch its own stock quote on its first call.

这是为了确保交易中的一致性-以便交易中的所有计算均基于相同的股价.

This is to try to ensure consistency within the transaction - so that all calculations within the transaction are based on the same stock price.

这类似于您可以配置JPA提供程序以仅从数据库中获取一次数据库行,然后使用缓存的值进行后续访问事务中同一数据库行的方式.

This would be similar to how you can configure JPA providers to only fetch a database row from the database once, and use the cached value for subsequent access to the same database row within the transaction.

有没有人提示如何实现这一目标?

Does anyone have tips on how this can be achieved?

推荐答案

这需要进行一些测试,但我认为您可以将报价单绑定到

This would require some testing but I think that you could bind the quote to a ThreadLocal and make your beans implement SessionSynchronization to unbind the quote from the ThreadLocal after the commit of a transaction (and thus implement a kind of transaction-scoped context).

这篇关于如何将数据附加到JTA交易? (或唯一标识)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆