Consider using ReaderWriterLock if you have many threads that < must read data , and these threads block waiting for a lock, and you don't often need to change the data.
However, ReaderWriterLock can block a thread that has been waiting for recording for a long time.
Therefore, use only ReaderWriterLock after you have confirmed that you will get a high conflict for locking in real life, "and you have confirmed that you cannot redesign your lock design to to reduce the lock time for .
Also, think about whether you can store the shared data stored in the database in the database and let them take care of all the locks, since this much less often gives you difficult tracking errors if the database is fast enough for your application.
In some cases, you can also use the Apsnet cache to process shared data and simply delete an item from the cache when the data changes. The next reading may put a new copy in the cache.
Remember
"The best kind of lock is you don't need a lock (i.e. don't exchange data between threads).
Ian Ringrose Jan 22 '10 at 11:52 2010-01-22 11:52
source share