performance - Closing over java.util.concurrent.ConcurrentHashMap inside a Future of Actor's receive method? -
i've actor want store mutable state inside map.
clients can send get(key:string)
, put(key:string,value:string)
messages actor.
i'm considering following options.
- don't use futures inside actor's receive method. in may have negative impact on both latency throughput in case i've large number of
gets/puts
because operations performed in order. - use
java.util.concurrent.concurrenthashmap
, invoke gets , puts insidefuture
.
given java.util.concurrent.concurrenthashmap
thread-safe , providers finer level of granularity, wondering if still problem close on concurrenthashmap inside future created each put , get.
i'm aware of fact it's bad idea close on mutable state inside future inside actor i'm still interested know if in particular case correct or not?
in general, java.util.concurrent.concurrenthashmap
made concurrent use. long don't try transport closure machine, , think through implications of being used concurrently (e.g. if read value, use function modify it, , put back, want use replace(key, oldvalue, newvalue)
method make sure hasn't changed while doing processing?), should fine in futures.
Comments
Post a Comment