点燃队列是否有一些方法来检查队列是否创建,就像缓存一样?
对于点燃缓存,我可以使用类似的东西:
if( txInfoCache.get(txType) == null ) {
txInfoCache.put(txType, new TreeMap<Long, InfoRecord>());
}
但是当我尝试使用它来处理队列时,它只是创建一个新的
CollectionConfiguration colCfg = new CollectionConfiguration();
IgniteQueue<InfoRecord> queue =
ignite.queue("ResultRecordQueue_" + txType, 0, null);
// never go into this judge
if (queue == null) {
queue = ignite.queue("ResultRecordQueue_" + txType, 0, colCfg);
}
最佳答案
我不太明白你的代码。首先,以下代码片段确定 txInfoCache
是否缓存包含给定键 txType
的条目如果它不包含与该键关联的条目,则会将指定的键与给定的值关联起来。
if(txInfoCache.get(txType) == null) {
txInfoCache.put(txType, new TreeMap<Long, InfoRecord>());
}
可以改为txInfoCache.putIfAbsent(txType, new TreeMap<Long, InfoRecord>())
.
至于你问题的第二部分,我刚刚检查了 Apache Ignite 2.4,它运行良好。 Ignite.queue(String name, int cap, @Nullable CollectionConfiguration cfg)
方法返回 null
如果指定队列不存在且 CollectionConfiguration
是 null
。请确保该队列不是之前创建的。
关于java - 点燃队列是否有一些方法来检查队列是否创建,就像缓存一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50059165/