synchronized(x) - how does it work?

I have an object with 3 internal caches that need to be updated, and I want to synchronize it for thread-safety but not excessively. ie, if I am updating cache #1 I only want to lock it, not any of the others. Does the following code work?:public my Object

{

privatestatic List cache1;

privatestatic List cache2;

privatestatic List cache3;

updateCache(List cache)

{

synchronized(cache){

//...update code

}

}

}

Thanks in advance.

[970 byte] By [YoungWinstona] at [2007-11-26 23:59:55]
# 1

synchronized(cache1) {

//...update code

}

synchronized(cache2) {

//...update code

}

synchronized(cache3) {

//...update code

}

This works fine.

cooper6a at 2007-7-11 15:49:22 > top of Java-index,Core,Core APIs...
# 2
Yes YoungWinston, your locking strategy should work (As long as you rename the class to a valid name, and include the class keyword ;-)
JasonChoya at 2007-7-11 15:49:22 > top of Java-index,Core,Core APIs...