write ResourceResolver.commit asynchronously? | Community
Skip to main content
New Participant
May 6, 2019 5:02 AM UTC
Solved

write ResourceResolver.commit asynchronously?

Hi to everybody,

I write a lot of values into JCR /var/xxx and close the operation with a ResourceResolver commit and a refresh.

My question was: does AEM perform the persistance operation asynchronously and should I wait with a EventHandler for these values? Or is it possible to continue without waiting?

Thanks in advance

Uwe

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
joerghoh
joerghohAccepted solution
Employee
May 6, 2019 10:44 AM UTC

that's working perfectly if you just read the data and don't run any query for that.

Jörg

4 replies

joerghoh
joerghohAccepted solution
Employee
May 6, 2019 10:44 AM UTC

that's working perfectly if you just read the data and don't run any query for that.

Jörg

Translate
joerghoh
Employee
May 6, 2019 10:29 AM UTC

Hi Uwe,

Actually it's both synchronous and asynchronous :-)

The write to the repository is happening synchronous. That means that after the .commit() returned you can read the data from the repository. Also the property indexes are updated synchronously.

But the lucene indexes are updated asnychronously. That means that a JCR query immediately after the commit() might return the nodes you have just updated (depending on the type of the index which is used for that specific JCR query).

HTH,

Jörg

Translate
UweGAuthor
New Participant
May 6, 2019 8:54 AM UTC

Hi,

thanks for clarification. Does perform .commit() a synchronious write into JCR?

This means, when I wake up the 2nd thread instantly after calling .commit() and when thread 2 is reading the data after calling resourceResolver.refresh(), get thread 2 all data? Or is it neccessary to sync thread 2 with a EventListener on JCR Level?

Thx

Uwe

Translate
arunpatidar
New Participant
May 6, 2019 7:11 AM UTC

A ResourceResolver is generally not thread safe! As a consequence, an application which uses the resolver, its returned resources and/or objects resulting from adapting either the resolver or a resource, must provide proper synchronization to ensure no more than one thread concurrently operates against a single resolver, resource or resulting objects.

ResourceResolver (Apache Sling 10 API)

Translate
Arun Patidar