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).
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?
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.