I have a web service endpoint that uses a mutable resource from a Java library. This web service endpoint can receive multiple requests at the same time. (endpoint implemented using Ring / Compojure). Creating these resources is expensive, so re-creating them for every web service call is really inefficient.
What I want to do is create a pool this resource, which I populate when the web service starts. Then, every time an endpoint is called, it takes a resource from the pool, uses it to process it, and then returns it to the pool and waits for the next call.
I am wondering what would be the best way to do this in Clojure? Is there a Clojure pool library that can help me?
I naively tried to implement this using a vector in an atom, where each element of the vector is this resource. However, he quickly realized that this could not work like that.
clojure pool
Neoasimov
source share