点燃缓存事务处理和 putAsync

Ignite cache transactioin and putAsync

我在事务中使用 Apache Ignite 缓存。目前我使用常规 cache.put() 方法,但想知道我是否应该更好地使用推荐的 putAsync()?如果使用异步方法,Transaction.commit() 是等待所有异步放置完成还是我必须在我的代码中执行此操作?

这将是我的简化代码:

Ignite ignite = Ignition.ignite();
IgniteTransactions transactions = ignite.transactions();
tx = transactions.txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.SERIALIZABLE, 10 * 1000, 0);

IgniteFuture fut = cache.putAsync("KEY", "VALUE");

fut.get(); // do I need to call this?

tx.commit();

是的,commit() 将等待异步方法完成。请注意,您只能同时拥有一个异步方法 运行ning - 如果您有一个,下一个将 运行 同步。