• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Concurrency and Thread-Safe Data Processing in Background Tasks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Concurrency and Thread-Safe Data Processing in Background Tasks


  • Subject: Re: Concurrency and Thread-Safe Data Processing in Background Tasks
  • From: Samuel Pelletier <email@hidden>
  • Date: Fri, 30 Aug 2013 16:31:52 -0400

Jérémy,

The ERXTaskObjectStoreCoordinatorPool.objectStoreCoordinator() is to use another database connection and to isolate the background process from the main user interface process. If you use the default ObjectStoreCoordinator, you will bloc the users with long database requests.

Even with another ObjectStoreCoordinator, your database server may impose lock depending on your connection setting and SQL.

To refresh objects, you need to force a fetch in the default ObjectStoreCoordinator, here is a code that should do it.

EOEditingContext _editingContextInDefaultEOObjectStore = new EOEditingContext(); 
_editingContextInDefaultEOObjectStore. setFetchTimestamp(System.currentTimeMillis());  // Tell the EC to fetch if snapshot is older than now
_editingContextInDefaultEOObjectStore.lock();  // do not forget that
try {
EOGlobalID globalIdToRefresh = _localCampaign.editingContext().globalIDForObject(_localCampaign);
EOEnterpriseObject refreshedObject = _editingContextInDefaultEOObjectStore.objectForGlobalID(globalIdToRefresh);
}
finally {
_editingContextInDefaultEOObjectStore.unlock();  // do not forget that
}

I think invalidating the snapshots will only affect future instances not existing ones.

Samuel


Le 2013-08-27 à 07:14, Jérémy DE ROYER <email@hidden> a écrit :

Hello,

According the the thread below :
- http://lists.apple.com/archives/webobjects-dev/2008/Aug/msg00088.html
and the slide :
- http://fr.slideshare.net/wocommunity/background-tasks

Only when using new EOEditingContext(ERXTaskObjectStoreCoordinatorPool.objectStoreCoordinator()) instead of new EOEditingContext(new EOObjectStoreCoordinator()) will propagate changes.
("Create a new ObjectStoreCoordinator (use Wonder OSC synchronization if you want changes to propogate)")

So I develop a new thread (for sending mass emails without slowing down all the users as currently)

I used :

a) 

I use new EOEditingContext(ERXTaskObjectStoreCoordinatorPool.objectStoreCoordinator()) for the thread


b) 

I add the code below each time I want changes to be propagated.

EOEditingContext _editingContextInDefaultEOObjectStore = new EOEditingContext(); 
_editingContextInDefaultEOObjectStore.invalidateObjectsWithGlobalIDs(new NSArray(new Object[]{ _editingContextInThreadObjectStoreCoordinator().globalIDForObject(_localCampaign) }));
_editingContextInDefaultEOObjectStore.invalidateObjectsWithGlobalIDs(new NSArray(new Object[]{ _editingContextInThreadObjectStoreCoordinator().globalIDForObject(_localCampaign._campagneTask()) }));

try {
_editingContextInDefaultEOObjectStore.saveChanges();
}
catch (Exception e) {
e.printStackTrace();

_editingContextInDefaultEOObjectStore.revert();
}

My task works well, changes are saved in the database…

…but changes are only propagate to the users (in the default EOObjectStore) when the do saveChanges() to their editingContext();

I tried using ERXEC.newEditingContext(ERXTaskObjectStoreCoordinatorPool.objectStoreCoordinator()); without any success.

Any idea where am I wrong ?

Jérémy
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
References: 
 >Concurrency and Thread-Safe Data Processing in Background Tasks (From: Jérémy DE ROYER <email@hidden>)

  • Prev by Date: Re: Ajax Sortable & Droppable together?
  • Next by Date: Re: Ajax Sortable & Droppable together?
  • Previous by thread: Concurrency and Thread-Safe Data Processing in Background Tasks
  • Next by thread: migrations and erjavamail?
  • Index(es):
    • Date
    • Thread