I have a multithreaded application written in Clojure. There is a problem of making a text in the console display correctly when multiple threads write to STDOUT. How can I do this correctly in Clojure, so the lines won’t look interlaced? I think this would involve some kind of separate IO agent, but I’m not really sure how to do that.
I have a multithreaded application written in Clojure. There is a problem of making
Share
Yes, that should work. Create an agent
(def printer (agent nil))and call it with the appropriateprintstatement, e.g,(send printer #(println msg)). The messages are put in a queue and are executed (asynchronously) one at a time.For logging purposes you could also look at
tools.loggingwhich uses agents under the hood.