Limiting the number of threads Compojure spawns

2019-04-15 23:37发布

问题:

I'm running compojure on Heroku. They have a limit of a 100 threads per process. So when I go over that limit, I get: java.lang.OutOfMemoryError: unable to create new native thread. Compojure is using the jetty ring adapter. Is there away of configuring the the server to only accept a hundred threads to the servlet at a time?

回答1:

The solution comes from Chris Perkins over at the compojure google group.

(run-jetty app {:configurator #(.setThreadPool % (QueuedThreadPool. 5))})

This initializes a QueuedThreadPool (with a concurrent limit of five threads) to the jetty instance, before it starts.