Inside ThreadPoolManager calling a service in background with Servlets request.getResourceResolver(). And its getting closed
private void setUpTreadPool() {
ModifiableThreadPoolConfig config = new ModifiableThreadPoolConfig();
config.setMinPoolSize(0); // if no work needs to be done, we don't need a thread hanging around
config.setKeepAliveTime(10000);
config.setPriority(ThreadPoolConfig.ThreadPriority.MIN);
myThreadPool = threadPoolManager.create(config, threadPoolName);
}
myThreadPool.execute(() -> {service(request.getResourceResolver();});
and executing with this call .
Views
Replies
Total Likes
May I know What you are expecting here?
If you open it, you are responsible for closing it
If you use a reference to the resourceResolver, then it is not your responsibility to close it
Best practice: https://cqdump.joerghoh.de/2018/11/14/try-with-resource-or-i-will-never-forget-to-close-a-resource-r...
Reference: http://ogeek.cn/qa/?qa=103260/
Hope that helps you!
Regards,
Santosh
The resourceResolver reference i am getting form the request.getResourceResolver() is getting closed when i use it from inside a ThreadPool without me closing it explicitly. How can i let it stay open as i cant adapt it to Session which i will need to use to get some results from a query
@mohibul_hasan_dhrubo Can you please pass complete code snippet here if possible? I can try to solve it. OR you can add it in a try catch block and use it within try
Refer to this: https://experienceleague.adobe.com/docs/experience-manager-cloud-manager/using/how-to-use/custom-cod...
myThreadPool.execute(() -> assetReferenceService.emailReport(request, response, finalToEmailList, finalCcEmailList, finalEmailBody, finalEmailSubject, request.resourceResolver()));
this service fetches the used and unused asset references by using `ReferenceSearch` api and then using the Day.CQ.Mailer service to send mail to users. I am calling this service in a separate thread. After passing the resourceResolver and using it to create a `Session` the resourceResolver throws `IllegalStateException` saying resourceResolver is already closed. I have circumvent this issue by using the Service User resourceResolver. but cant use it for some restrictions thats why trying to understand why the resourceResolver is getting closed and if there any alternative solution for that.
what is the service() method doing with the resourceResolver?
myThreadPool.execute(() -> assetReferenceService.emailReport(request, response, finalToEmailList, finalCcEmailList, finalEmailBody, finalEmailSubject, request.resourceResolver()));
this service fetches the used and unused asset references by using `ReferenceSearch` api and then using the Day.CQ.Mailer service to send mail to users. I am calling this service in a separate thread. After passing the resourceResolver and using it to create a `Session` the resourceResolver throws `IllegalStateException` saying resourceResolver is already closed. I have circumvent this issue by using the Service User resourceResolver. but cant use it for some restrictions thats why trying to understand why the resourceResolver is getting closed and if there any alternative solution for that.
Views
Likes
Replies