This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
How a read write lock enabled resource (collection) know which are all are read threads and which all are write threads ?
The collection doesn't know or care if a thread is all read or all write operations. All it knows is which of its own methods are read methods and which of its own methods are write methods. It then protects its own methods with an appropriate lock. So a thread that does all reads will only get read locks, a thread which does all writes gets only write locks, and a thread which reads sometimes and which writes other times will get a read lock when it reads and a write lock when it writes.