Skip to Content
3
Dec 26, 2018 at 04:09 PM

How to use Parallel Streams with Hybris?

820 Views

i'm trying to use Java 8 parallel streams like so:

     bigList.parallelStream().forEach(item -> {
       foo();
     });

But I'm getting the following error:

 Caused by: java.lang.IllegalStateException: no tenant active. if you do not want to use tenants, call Registry.activateMasterTenant() to assure the Master tenant is active.

I did place this tenant check in the "foo" method:

     if (!Registry.hasCurrentTenant())
     {
         Registry.activateMasterTenant();
     }

but the error still happens.

Stacktrace:

 at de.hybris.platform.core.Registry.getCurrentTenant(Registry.java:823)
 at de.hybris.platform.util.Config.getBoolean(Config.java:245)
 at de.hybris.platform.util.persistence.PersistenceUtils.isPersistenceLagacyModeEnabledInConfig(PersistenceUtils.java:69)
 at de.hybris.platform.util.persistence.PersistenceUtils.isPersistenceLegacyModeEnabled(PersistenceUtils.java:64)
 at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.isSLDPersistence(DefaultModelService.java:477)
 at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.preloadItems(DefaultModelService.java:467)
 at de.hybris.platform.servicelayer.search.internal.resolver.impl.DefaultModelResolver.preloadItems(DefaultModelResolver.java:95)
 at de.hybris.platform.servicelayer.search.impl.LazyLoadModelList.loadPage(LazyLoadModelList.java:62)
 at de.hybris.platform.core.LazyLoadItemList.switchPage(LazyLoadItemList.java:217)
 at de.hybris.platform.core.LazyLoadItemList.switchBufferedPageNoLock(LazyLoadItemList.java:473)
 at de.hybris.platform.core.LazyLoadItemList.switchBufferedPageSynchronized(LazyLoadItemList.java:465)
 at de.hybris.platform.core.LazyLoadItemList.switchBufferedPage(LazyLoadItemList.java:460)
 at de.hybris.platform.core.LazyLoadItemList.getOrSwitchBufferedPage(LazyLoadItemList.java:451)
 at de.hybris.platform.core.LazyLoadItemList.getOrSwitchBufferedPage(LazyLoadItemList.java:431)
 at de.hybris.platform.core.LazyLoadItemList.getBuffered(LazyLoadItemList.java:109)
 at de.hybris.platform.core.LazyLoadItemList.get(LazyLoadItemList.java:95)
 at java.util.AbstractList$Itr.next(AbstractList.java:358)
 at de.hybris.platform.core.internal.BaseLazyLoadItemList$1.next(BaseLazyLoadItemList.java:177)
 at java.util.Spliterators$IteratorSpliterator.trySplit(Spliterators.java:1784)
 at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
 at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
 at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
 at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
 at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
 at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Any ideas?