Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

write ResourceResolver.commit asynchronously?

Avatar

Level 1

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

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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

Jörg

View solution in original post

4 Replies

Avatar

Community Advisor

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)



Arun Patidar

Avatar

Level 1

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

Avatar

Employee Advisor

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

Avatar

Correct answer by
Employee Advisor

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

Jörg