ldnclj

Find us on #clojure-uk
pupeno 2015-08-28T07:59:21.000043Z

Good morning.

thomas 2015-08-28T08:11:40.000044Z

Ma Tie

pupeno 2015-08-28T08:20:01.000045Z

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.

thomas 2015-08-28T09:00:59.000046Z

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

pupeno 2015-08-28T09:01:26.000047Z

@thomas: they are.

thomas 2015-08-28T09:15:57.000048Z

@pupeno: wrap them with a synchronised maybe?

pupeno 2015-08-28T09:16:53.000049Z

thomas: do you mean locking? https://clojuredocs.org/clojure.core/locking

thomas 2015-08-28T09:18:12.000050Z

No I meant some Java code that uses synchronised

thomas 2015-08-28T09:18:30.000051Z

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

pupeno 2015-08-28T09:18:33.000052Z

thomas: I’m not writing the Java code.

pupeno 2015-08-28T09:18:40.000053Z

And I’d rather not add Java code.

pupeno 2015-08-28T09:19:00.000054Z

I’m just using one of these: http://docs.oracle.com/javase/7/docs/api/javax/script/ScriptEngine.html

mccraigmccraig 2015-08-28T10:27:42.000055Z

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

pupeno 2015-08-28T10:28:39.000057Z

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.

mccraigmccraig 2015-08-28T10:52:16.000058Z

jetty can certainly use a threadpool - http://www.eclipse.org/jetty/documentation/current/quickstart-config-what.html#intro-jetty-configuration-server

pupeno 2015-08-28T14:08:21.000059Z

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

2015-08-28T14:19:44.000060Z

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

pupeno 2015-08-28T14:25:07.000061Z

ragge: I’m using aleph.flow

2015-08-28T14:26:27.000062Z

ok, cool