It seems pretty clear that using readLock when reading from a file (for example), and using writeLock when writing to it is appropriate. However, if I have an operation where two values are being compared, such as:
if (i == j) {
System.out.println("equal);
}
Then is it okay to use readLock() instead of writeLock to lock this code? Granted, I'm not writing anything, but I am comparing two values, which is bit different than just reading data since there is an operation involved. Keep in mind that "i" or "j" could change at any time. In theory, readLock() will only move forward if a writeLock() is not modifying the resource, but I may not fully understand all the complexities of this issue. It just seems like there is potential for a bit of a grey area so I thought I'd get some input.
Thanks to everyone,
Matt