Hi @supportmember
In Java 7 the idiom “try-with-resource” has been introduced in the java world. It helps to never forget to close a resource. And since Sling 9, the ResourceResolver interface implements the AutoCloseable marker interface, so the try-with-resource idiom can be used.
That means, that you can and should use this approach:
try (ResourceResolver resolver = getResourceResolver) {
// do something with the resolver
// no need to close it explicitly, it's closed automatically
}
With this approach you omit the otherwise obligatory finally block to close the resource resolver (which can be forgotten...)
This approach helps to reduce boilerplate code and eliminates some potential for errors.
When you redeploy the code, it will restart the bundle only specific to the project, but the complete OSGi service will not be restarted. It will not close the current threads and requires a restart. You can see the SessionStatistics objects in the JMX console(http://localhost:4502/system/console/jmx).
So after applying the fix, you will need to do a restart of the instance which will restart the complete OSGi service by closing all the ongoing/blocked threads.
Thanks!