|
7/8 |
2006/1/23-25 [Computer/SW/Languages/Java] UID:41480 Activity:nil |
1/23 I'm trying to make somebody else's code thread-safe and it seems like my synchronization blocks are not being respected. Does anyone know a problem with this code? class FooPoller { protected static Boolean lock = new Boolean(true); private static void poll() { // do some stuff synchronized(lock) { // modify some static member objects } } Public void addToList(Vector addable) { // do some stuff synchronized(lock) { // modift some static member objects } } } I then have one thread calling FooPoller.poll() in a loop, while some other thread is calling addToList() on an instance of a subclass of FooPoller. Do the instance method and the static method see a different lock? Do the base class and the subclass see a different lock? This is really stumping me. -dgies \ What Java version? Perhaps something weird is happening with Boolean autoboxing if >=1.5. Try an Object instance as the lock. - gojomo \_ did you revolve this? |
7/8 |
|