Hello all,
I am wondering on the usage of the resource resolver and on how long it should
stay open. Lets say I have the following implementation:
@Component
@Service(SomeService.class)
public class SomeServiceImpl implements SomeService {
@Reference
private ResourceResolverFactory resourceResolverFactory;
private ResourceResolver resourceResolver;
@Activate
protected synchronized void activate(Map<String, Object> properties) throws
Exception {
try {
resourceResolver =
resourceResolverFactory.getAdministrativeResourceResolver(null);
} catch (LoginException e) {
LOG.error("Failed to get admin resourceresolver", e);
throw e;
}
}
@Deactivate
protected synchronized void deactivate(Map<String, Object> properties)
throws Exception {
if (resourceResolver != null && resourceResolver.isLive()) {
resourceResolver.close();
}
}
public void doSomething(String path) {
Resource resource = resourceResolver.getResource(path);
//do something
}
}
Is there anything wrong on using this? Knowing that this means the
resourceresolver will stay open for possible months/years…
Or should one try and make the resourceresolver opening as short as possible?
Knowing that the method will be called around 1000-2000 times an hour.
Another solution is of course passing the resourceResolver to do the
doSomething, but then the question still remains, how long should you keep a
resourceresolver open
Greetings,
Roy