Good morning.
Ma Tie
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.
@pupeno: just out of interest: are these object Java objects?
@thomas: they are.
@pupeno: wrap them with a synchronised maybe?
thomas: do you mean locking? https://clojuredocs.org/clojure.core/locking
No I meant some Java code that uses synchronised
(Just thinking out loud here, that might not do the trick of course)
thomas: I’m not writing the Java code.
And I’d rather not add Java code.
I’m just using one of these: http://docs.oracle.com/javase/7/docs/api/javax/script/ScriptEngine.html
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
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.
jetty can certainly use a threadpool - http://www.eclipse.org/jetty/documentation/current/quickstart-config-what.html#intro-jetty-configuration-server
mccraigmccraig: my library can’t depend on a particular jetty configuration.
@pupeno: apache commons pool might be worth a look: https://commons.apache.org/proper/commons-pool/
ragge: I’m using aleph.flow
ok, cool