Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala-way for managing object pools

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?

like image 350
ayvango Avatar asked Sep 25 '12 02:09

ayvango


1 Answers

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.

like image 110
3 revs Avatar answered Sep 20 '22 21:09

3 revs