cancel
Showing results for 
Search instead for 
Did you mean: 

Sessionservice Issue in ThreadPoolExecutor

Former Member
0 Kudos

Hello,

for an XML-based product import I am trying to run multiple consumer threads for the product import. As part of the import process my Runnable tries to load a product before importing it. I am using the method DefaultProductService.getProductForCode to retrieve the product. The injected product service instance is shared among the threads in the thread pool. Unfortunately when I run the import as an integration test I receive the following Stacktrace:

] Exception in thread "pool-5-thread-1" java.lang.NullPointerException [yunitint] at de.hybris.platform.servicelayer.session.impl.DefaultSessionService.executeInLocalView(DefaultSessionService.java:94) [yunitint] at de.hybris.platform.servicelayer.search.impl.DefaultFlexibleSearchService.getJaloResult(DefaultFlexibleSearchService.java:396) [yunitint] at de.hybris.platform.servicelayer.search.impl.DefaultFlexibleSearchService.search(DefaultFlexibleSearchService.java:168) [yunitint] at de.hybris.platform.servicelayer.internal.dao.DefaultGenericDao.find(DefaultGenericDao.java:53) [yunitint] at de.hybris.platform.product.daos.impl.DefaultProductDao.findProductsByCode(DefaultProductDao.java:117) [yunitint] at de.hybris.platform.product.impl.DefaultProductService.getProductForCode(DefaultProductService.java:175) [yunitint] at X.core.services.impl.DefaultXImportService$ProductImportTask.loadOrCreateProduct(DefaultXService.java:671) [yunitint] at X.core.services.impl.DefaultXImportService$ProductImportTask.run(DefaultXImportService.java:614) [yunitint] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [yunitint] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [yunitint] at java.lang.Thread.run(Thread.java:745)

It seems as if the session service returns a null session but I do not understand why this is the case nor how to fix it.

Accepted Solutions (1)

Accepted Solutions (1)

former_member537989
Contributor
0 Kudos

In order to be more configuration friendly, you can achieve the same by creating your own tenantAwareTaskExecutor

 <bean id="tenantAwareTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
         <property name="threadFactory">
             <bean class="YourCustomThreadFactoryClass extends TenantAwareThreadFactory">
                 <constructor-arg value="#{T(de.hybris.platform.core.Registry).getCurrentTenant()}" />
                 <property name="catalogVersionService" ref="catalogVersionService" />
                 <property name="sessionService" ref="sessionService" />
                 <property name="userService" ref="userService" />
             </bean>
         </property>
     </bean>

Former Member
0 Kudos

Accepted for more elegant solution :)

Answers (1)

Answers (1)

Former Member
0 Kudos

I've been able to solve this problem. The cause was that spawned-off threads do not have an associated JaloSession nor an active tenant. So all I needed to do was to execute the following lines of code in the run-method (NOT in the constructor!) of my Runnable:

 if (!Registry.hasCurrentTenant()) {
     Registry.setCurrentTenant(Registry.getTenantByID("junit"));
 }
 JaloSession.getCurrentSession().activate();