Do you use lock in your web applications?
<p>After posting this question:</p>

<p><a href="http://stackoverflow.com/questions/781189/how-to-lock-on-an-integer-in-c">http://stackoverflow.com/questions/781189/how-to-lock-on-an-integer-in-c</a></p>

<p>Many of the answers made me feel that I'm a 'sinner' for using lock in my web apps. I never thought this is a problem (if used wisely), what about you? Do you ever use it in your web applications?</p>

<p>I don't see how a web application can be written without locking, for example if you want to load some data from a database and you want to be sure that no other thread will load it (also for singletons), normally you use locking, for example:</p>

<pre><code>private _locker =  new object();
private YourClass[] _data;
public YourClass[] Data
{
    get
    {
        if(_data == null)
        {
            lock( _locker)
            {
                // get your data
               _data = GetYourData();
            }
        }
        return _data;
    }
}
</code></pre>

<p>Is there a problem with this?!</p>

<p>Edit:</p>

<p>Please note that I'm referring to a single server scenario here, for a server farm you need some distributed locking mechanism, but you don't expect every site you create to get millions of hits in a couple of weeks, do you? What if you need locking, should you create your site with that distributed locking, isn't that too much for an application which you have no idea whether it will ever need to be scaled or not? Besides computers have gotten really fast these days, one server can handle tons of traffic and this has been proven so many times, some examples are plentyoffish.com and this very site you're using right now, do some googling and I'm sure you'll come across so many others.</p>
