java - 点燃缓存事务和 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();
解决方案
是的,commit() 将等待异步方法完成。请注意,您只能同时运行一个异步方法 - 如果您有一个,则下一个将同步运行。
推荐阅读
- rust - 为什么在多个文件中使用结构时会出现“预期的结构文件 1::A 找到结构文件 2::A”错误?
- sql - 根据数据类型格式化日期列的 SQL 语句
- android - 当用户使用 rxbinding 和 rxjava 重复点击获取数据按钮时,不要重新执行请求
- c++ - 将映射从文件传递到 C++ 类
- java - 在 JUnit 测试中强行抛出异常
- sql - 基于一列的子字符串组合类似的行?
- python - 删除重复时间,但保留最大值 xarray
- javascript - True 时跳转到下一页
- python - 关闭 Selenium 弹出窗口
- flutter - 每秒调用服务器 api 以获取实时数据是否很好?