首页 > 解决方案 > 点燃缓存事务和 putAsync

问题描述

我将 Apache Ignite Cache 与事务一起使用。目前我使用常规的 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();

标签: javaignite

解决方案


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


推荐阅读