Fork me on GitHub
#ldnclj
<
2015-08-28
>
Pablo Fernandez08:08:01

Does anybody have a recommendation on libraries to make a pool of resources in Clojure? My goal is to have some objects that are slow to create, so I want to re-use them over time, but they are not thread safe, so no two threads should be using one at the same time.

thomas09:08:59

@pupeno: just out of interest: are these object Java objects?

thomas09:08:57

@pupeno: wrap them with a synchronised maybe?

thomas09:08:12

No I meant some Java code that uses synchronised

thomas09:08:30

(Just thinking out loud here, that might not do the trick of course)

Pablo Fernandez09:08:33

thomas: I’m not writing the Java code.

Pablo Fernandez09:08:40

And I’d rather not add Java code.

mccraigmccraig10:08:42

pupeno: the very simplest option would be a lazily created thread-local (via a dynamic var or wrapping java.lang.ThreadLocal ... otherwise there seem to be a few clojure pools on github, though since one is by ztellman you should probably use that one : https://github.com/ztellman/dirigiste

Pablo Fernandez10:08:39

Yeah, I though thread local would work, but jetty seems to be spawning new threads per each request, they don’t get re-used, so it kills the goal of re-usability.

Pablo Fernandez14:08:21

mccraigmccraig: my library can’t depend on a particular jetty configuration.

ragge14:08:44

@pupeno: apache commons pool might be worth a look: https://commons.apache.org/proper/commons-pool/

Pablo Fernandez14:08:07

ragge: I’m using aleph.flow