How to achieve exclusive writing but non-exclusive reading?

How can I achieve exclusive writing but non-exclusive reading? Can I synchronizeaccess the installer and make a variable volatile? is that enough?

+5
source share
1 answer

Look at the Java5 parallel api:

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html

This will satisfy your requirement, as you can allow multiple threads to read without locking and locking only when writing.

Here's an interesting post comparing this api with a traditional synchronous read: ReentrantReadWriteLock vs synchronized

, @assylias , , .

, volatile , :

. , :

_ , .

_ .

+6

All Articles