What is the preferred way in scala for managing object pools?
I need to create and delete large scale of objects single-threaded (no need for synchronization) . In c++ I've used array of static objects.
What is idiomatic and effective way to cope with it in scala?
I would wrap it in an Actor. If you are not familiar, check out Akka: http://doc.akka.io/docs/akka/2.0.3/scala/actors.html
This is a pretty good example: https://github.com/derekjw/fyrie-redis/blob/master/src/main/scala/net/fyrie/redis/ConnectionPool.scala
The actor model allows you to guarantee single-threaded access because actors process incoming messages one at a time. This leads to very simple code inside the actor and a very simple API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With