Does the ResourceResolverFactory create a thread safe ResourceResolver? | Community
Skip to main content
Art_Bird
Level 2
Apr 12, 2023 1:56 PM UTC
Solved

Does the ResourceResolverFactory create a thread safe ResourceResolver?

I need a thread safe ResourceResolver that can be used for CRUD operations but nothing says using the ResourceResolverFactory is or isn't thread safe.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Apr 12, 2023 2:51 PM UTC
ResourceResolver is as stated not thread safe, therefore it should not
be used concurrently by different threads. However, if you create the
resource resolver through the factory yourself you can pass it on to
another thread.

Reference : https://www.mail-archive.com/users@sling.apache.org/msg03803.html  

Arun Patidar

3 replies

Siva_Sogalapalli
New Participant
Apr 12, 2023 2:15 PM UTC

Hi @art_bird 

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. Please check below links for more info. 

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/org/apache/sling/api/resource/ResourceResolver.html 

https://kiransg.com/2021/11/07/aem-resource-resolver-commit-save-best-practices/ 

Translate
Art_Bird
Art_BirdAuthor
Level 2
Apr 12, 2023 2:30 PM UTC

I understand the ResourceResolver isn't thread safe.

 

My question is a ResourceResolver that has been created using the ResourceResolverFactory considered thread safe?

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Apr 12, 2023 2:51 PM UTC
ResourceResolver is as stated not thread safe, therefore it should not
be used concurrently by different threads. However, if you create the
resource resolver through the factory yourself you can pass it on to
another thread.

Reference : https://www.mail-archive.com/users@sling.apache.org/msg03803.html  

Translate
Arun Patidar