0
Got started looking at Hazelcast(3.4.4)。最小配置。測試:Hazelcast總是返回null,containsKey總是返回false
case class Ticket(id:Int, name:String)
val ticketCount = 20
val tickets:List[Ticket] = for { n <- (0 until ticketCount).toList } yield Ticket(n, s"ticket$n")
val map: IMap[Long, Ticket] = hz1.getMap[Long,Ticket]("com.foo.testmap")
tickets foreach { t =>
println(s"submitting $t")
Thread.sleep(10) // some delay to submit one ticket
map.putIfAbsent(t.id, t)
}
Thread.sleep(2000) // two seconds to make sure all is set..
var value1 = map.get(19) // null
var value2 = map.containsKey(19)) // false
val value3 = map.getAsync(19).get() // Ticket(19,ticket19)
爲什麼null
,爲什麼false
,爲什麼只有map.getAsync(19).get()
作品?
這一點,雖然:
val iterator = map.entrySet().iterator() // will print all values
while(iterator.hasNext) {
val next = iterator.next()
println(next)
}
將打印的所有條目。
更新:
在配置:
<map name="com.foo.testmap">
<in-memory-format>OBJECT</in-memory-format>
</map>
好趕上..謝謝。 – ses