1.

Should I Use Readerwriterlock Instead Of Monitor.enter/exit?

Answer»

Maybe, but be careful. ReaderWriterLock is USED to allow multiple threads to read from a data source, while still granting exclusive ACCESS to a single writer THREAD. This makes sense for data access that is mostly read-only, but there are some caveats. First, ReaderWriterLock is relatively poor performing compared to Monitor. Enter/Exit, which offsets some of the benefits. Second, you need to be very sure that the data structures you are accessing fully support multithreaded read access. Finally, there is APPARENTLY a bug in the v1.1 Reader Writer Lock that can cause starvation for writers when there are a large number of readers. IAN Griffiths has some interesting discussion on Reader Writer Lock here and here.

Maybe, but be careful. ReaderWriterLock is used to allow multiple threads to read from a data source, while still granting exclusive access to a single writer thread. This makes sense for data access that is mostly read-only, but there are some caveats. First, ReaderWriterLock is relatively poor performing compared to Monitor. Enter/Exit, which offsets some of the benefits. Second, you need to be very sure that the data structures you are accessing fully support multithreaded read access. Finally, there is apparently a bug in the v1.1 Reader Writer Lock that can cause starvation for writers when there are a large number of readers. Ian Griffiths has some interesting discussion on Reader Writer Lock here and here.



Discussion

No Comment Found