Monday, 14 January 2008

IHttpHandler IsReusable Property

There isn't much clear info regarding this property on the net. It can be better in terms of performance when the property is set to true, but can cause some headaches if you have set it to true in the wrong scenario.

public bool IsReusable
{
   get
   {
      return false;
   }
}

The property is used to indicate if a single intantiation of your IHttpHandler implementation can be used to process multiple concurrent requests. Each client request is considered to be a worker thread on the serverside when being processed through the ASP.NET pipeline. So, if we set IsReusable = true, we need to make sure that our ProcessRequest method is threadsafe. The ProcessRequest should not rely on any state that could be modified by other concurrent request threads. Important when your IHttpHandler implementation does expensive initialisations, otherwise it probabaly doesn't really matter if you return true or false (since simple object allocation is fairly inexpensive in .NET). N.B. Pages are never pooled.

3 comments:

Anonymous said...

Thanks!! The online docs made no sense, and you cleared it up for me.

Anonymous said...

Neil, I am confused. It's not clear what IsReusable=true really does. To me it can mean one of two things: a) Pooling: ProcessRequest() still can't be re-entered from another thread while the first one has not finished, but instance is not destroyed after ProcessRequest() is finished, thus saving on the cost of constructing and destructing the instance; and b) Singleton: ProcessRequest() is truly thread-safe, and the same instance's ProcessRequest() can be called by multiple threads without waiting for other threads finishing ProcessRequest(), in which case IHttpHandler instance could behave as a singleton.

From your post is seems you indicate it's scenario B, but is it the case?

Anonymous said...

米蘭情趣用品情趣用品情趣飛機杯自慰套充氣娃娃AV女優按摩棒跳蛋潤滑液角色扮演情趣內衣自慰器穿戴蝴蝶變頻跳蛋無線跳蛋電動按摩棒情趣按摩棒丁字褲G點SM後庭

視訊美女視訊做愛


網頁設計
網頁設計