EOEditingContexts with same Object store, different threads
EOEditingContexts with same Object store, different threads
- Subject: EOEditingContexts with same Object store, different threads
- From: Jeff Schmitz <email@hidden>
- Date: Sat, 04 Oct 2008 22:40:00 -0500
Hello, I'm trying to run three threads that perform long calculations on data within the object space. Each thread needs to check EO states set by the other threads at certain intervals to make sure that it isn't working on the same calculations as other threads. When checking these states, each thread goes through a common sync point object of class PoolSync that has syncronized methods.
public class PoolSync {
public synchronized boolean checkAndLock(Pool pool, String threadName, EOEditingContext ec) { System.out.println("checkAndLock called by " + threadName + "for pool " + pool.name()); if (!(pool.calculating())) { pool.calculating(true); ec.saveChanges(); System.out.println("setCalculating true " + threadName + " for pool " + pool.name()); return true; } else { System.out.println("checkAndLock returning false " + threadName + "for pool " + pool.name());
return false; } }
}
I've set up each thread with its own editing context, with each having the same parent ObjectStoreCoordinator using the following code:
EOObjectStoreCoordinator parentObjectStore = new EOObjectStoreCoordinator(); EOEditingContext thread1EditingContext = ERXEC.newEditingContext(parentObjectStore); EOEditingContext thread2EditingContext = ERXEC.newEditingContext(parentObjectStore); EOEditingContext thread3EditingContext = ERXEC.newEditingContext(parentObjectStore);
This is the call thread1 makes:
poolSync.checkAndLockForCanIWins(pool, threadName, thread1EditingContext)
While the synchronized class seems to work as expected based on my IO output below, the editing contexts in each thread don't seem to be being kept up to date with states set from other threads. I was under the impression that WO would do this for me automatically as soon as saveChanges was called as long as they shared the same parent ObjectStoreCoordinator. Is that not the case?
Note that even though thread 1 sets pool.calculating to true for TESTPOOL, threads 2 and 3 later read the pool.calculating() state as False.
checkAndLock called by Thread 1for pool TESTPOOL setCalculating true Thread 1 for pool TESTPOOL checkAndLock called by Thread 3for pool TESTPOOL setCalculating true Thread 3 for pool TESTPOOL checkAndLock called by Thread 2for pool TESTPOOL setCalculating true Thread 2 for pool TESTPOOL
Thanks! Jeff |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden