I am using ring.adapter.jetty/run-jetty
to serve my http requests. As I understand the newer versions of Jetty server do NOT uniquely assign a thread to every incoming request. Instead, they leverage the java.nio
async libraries to return the thread to the thread pool when a thread blocks on a IO task (say database call).
I think this question might apply to the JVM platform in general but if I am writing a simple http CRUD application in Clojure using ring-jetty-adapter 1.8.2
, then;
- Does my thread get blocked during the IO (reading/writing to db) or does it get returned to the thread pool? If it gets returned to the thread pool during the blocking phase, then how does it know that an IO heavy task is coming up because at no place in the code do we indicate that we are doing an IO heavy task.
- If it gets blocked then I am wasting the precious thread’s time. How can indicate to Jetty that the thread should be returned to the thread pool.