Object locking private class members - best practice? (Java)
问题 I asked a similar question the other day but wasn't satisfied with the response, mainly because the code I supplied had some issues that people focused on. Basically, what is the best practice for locking private members in Java? Assuming each private field can only be manipulated in isolation and never together (like in my Test class example below), should you lock each private field directly (example 1), or should you use a general lock object per private field you wish to lock (example 2)?