scala-way for managing object pools

1.6k Views Asked by At

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?

1

There are 1 best solutions below

0
On

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.