问题
Hazelcast 3.4.4.
I got a situation when map.getAsync
returns null no matter what. It even if timeout set to 10000000
, TimeUnit.SECONDS
it doesn't wait.
But if I put Thread.sleep(10000)
just before getAsync then it returns proper value from the map.
I wonder what's wrong and how I could check/fix/undersand it?
UPDATE: if I remove import ExecutionContext.Implicit.global
from my code and all dependencies (like Scala.concurent.Future
), then getAsync starts working again. But I'm not satisfied still ...
回答1:
To me it feels like you expect it to wait until a value is put into the map, doesn't it?
It doesn't mean that it will wait until a value becomes available, it just gives you the option to have a timeout for the case the cluster is totally exhausted and cannot answer your request fast enough.
I actually think there is no good way to achieve what you're looking for but you could use the local EntryListeners, waiting for a key and forward the event through a topic, if that makes sense. You might also need a Promise kind of implementation.
回答2:
Not sure if it's an issue with 3.4.4, but 3.5.1 works (from REPL):
scala> import scala.concurrent._
import scala.concurrent._
scala> import ExecutionContext.Implicits.global
import ExecutionContext.Implicits.global
scala> val map = hz.getMap[String, Int]("map")
map: com.hazelcast.core.IMap[String,Int] = IMap{name='map'}
scala> map.set("one", 1)
scala> map.getAsync("one").get()
res4: Int = 1
来源:https://stackoverflow.com/questions/31974762/getasynckey-gettimeout-sec-doesnt-wait-return-null