Does the ResourceResolverFactory create a thread safe ResourceResolver? | Community
Skip to main content
Art_Bird
Level 2
April 12, 2023
Solved

Does the ResourceResolverFactory create a thread safe ResourceResolver?

  • April 12, 2023
  • 1 reply
  • 1434 views

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.
Best answer by arunpatidar
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  

1 reply

Siva_Sogalapalli
Community Advisor
Community Advisor
April 12, 2023

Hi @art_bird 

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/ 

Art_Bird
Art_BirdAuthor
Level 2
April 12, 2023

I understand the ResourceResolver isn't thread safe.

 

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

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
April 12, 2023
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