Does creating a nonclustered index on a SQL Server 2005 table prevent selects?

I’d like to create an index on a view I have but I need to make sure the data can still be read while the index is being created. I was reading an article that suggested that when creating a nonclustered index that the data is still readable if you specify the ONLINE=ON option (example … Read more

What’s blocking “Select top 1 * from TableName with (nolock)” from returning a result?

I’m currently running the following statement select * into adhoc..san_savedi from dps_san..savedi_record It’s taking a painfully long time and I’d like to see how far along it is so I ran this: select count(*) from adhoc..san_savedi with (nolock) That didn’t return anything in a timely manner so for the heck of it I did this: … Read more

Can ToArray() throw an exception?

While the answer to this question is excellent, it implies that you should surround calls to List.ToArray() in a lock for concurrency. this blog post also implies that it could fail catastrophically (but rarely). I typically use ToArray rather than a lock in when enumerating Lists or other collections in order to avoid the “Collection … Read more

ConcurrentHashMap vs ReentrantReadWriteLock based Custom Map for Reloading

Java Gurus, Currently we have a HashMap<String,SomeApplicationObject> which is being read frequently and modified occasionally and we are having issues that during the modification/reloading, Read operation returns null which is not acceptable. To fix this I have following options: A. Use ConcurrentHashMap Which looks like the first choice but the operation which we are talking … Read more

Locking on field or local variable?

After I read this question with an answer from Marc…. I sometimes see people locking on a local variable. Is this code broken? public void Do() { object o = new Object(); lock (o) { … } } I believe object o = new Object(); should be outside the method as a Field. Since each … Read more

Acquiring advisory locks in postgres

I think there must be something basic I’m not understanding about advisory locking in postgres. If I enter the following commands on the psql command line client, the function returns true both times: SELECT pg_try_advisory_lock(20); –> true SELECT pg_try_advisory_lock(20); –> true I was expecting that the second command should return false, since the lock should … Read more

ReaderWriterLockSlim Extension Method Performance

I’ve been playing with collections and threading and came across the nifty extension methods people have created to ease the use of ReaderWriterLockSlim by allowing the IDisposable pattern. However, I believe I have come to realize that something in the implementation is a performance killer. I realize that extension methods are not supposed to really … Read more

What is wrong with locking non-static fields? What is the correct way to lock a particular instance?

Why is it considered bad practice to lock non-static fields? And, if I am not locking non-static fields, then how do I lock an instance method without locking the method on all other instances of the same or derived class? I wrote an example to make my question more clear. public abstract class BaseClass { … Read more