I am looking for clarification on the answers to this question.
The top two answers are somewhat contradictory on the thread safety requirements of a reusable handler.
Can a IHttpHandler instance be used to process multiple requests concurrently, requiring it to be fully thread safe?
or
Will it only ever process multiple requests consecutively, requiring only that the state of the handler is not changed in the ProcessRequest method?
Update (6/5/15):
I have been reviewing the source code for HttpApplication again here to try and get a answer to this.
My take is:
Requests are mapped to IHttpHandlers by a HttpApplication instance in MapHttpHandler.
MapHttpHandler uses a collection of HanlderFactoryCache's private to the HttpApplication instance. See GetFactory.
HanlderFactoryCache returns a HttpHandlerWrapper for IHttpHandler mappings, which manages a single IHttpHandler instance, and the IsReusable property is handled in HttpHandlerWrapper.ReleaseHanlder.
So any reuse of a handler will be scoped to a HttpApplication instance and as HttpApplication instances are not used concurrently (see Life Cycle Events and Global.asax file here) this all suggests:
- Returning true from IHttpHanlder.IsReusable leverages the existing HttpApplication object pool to reuse instances of the IHttpHanlder.
- IHttpHanlders do not have to be thread safe to take advantage of the built in instance reuse in ASP.NET.
The issue is if I'm wrong I could create some pretty big problems for myself and lots of people who have an opinion on this subject seem to think I'm wrong.
Can anyone show me where I've read the code wrong? Can anyone confirm my interpretation?
Note: I'm further convinced by the fact HttpApplication itself is a reusable IHttpHanlder that does not appear to be thread safe.