on 2018 Oct 04 10:40 AM
Hi Guys, Can anyone help me to know- how can I register my custom thread created in hybris.
My code sample:
final Runnable runnable = () -> { // my code here.. }; final Thread t = new Thread(runnable); t.start();
If I use t.run() in place of t.start() then my code inside the runnable is getting executed but if I use t.start() then code inside the runnable is not getting executed and I am getting error saying:
Exception in thread "Thread-134" java.lang.IllegalStateException: no tenant active. if you do not want to use tenants, call Registry.activateMasterTenant() to assure the Master tenant is active. INFO | jvm 1 | main | 2018/10/01 15:35:52.038 | at de.hybris.platform.core.Registry.getCurrentTenant(Registry.java:804) at de.hybris.platform.util.Config.getBoolean(Config.java:245) INFO | jvm 1 | main | 2018/10/01 15:35:52.038 | at de.hybris.platform.util.persistence.PersistenceUtils.isPersistenceLagacyModeEnabledInConfig(PersistenceUtils.java:68) INFO | jvm 1 | main | 2018/10/01 15:35:52.038 | at de.hybris.platform.util.persistence.PersistenceUtils.isPersistenceLegacyModeEnabled(PersistenceUtils.java:63) INFO | jvm 1 | main | 2018/10/01 15:35:52.038 | at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.isSLDPersistence(DefaultModelService.java:476) INFO | jvm 1 | main | 2018/10/01 15:35:52.038 | at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.preloadItems(DefaultModelService.java:466) INFO | jvm 1 | main | 2018/10/01 15:35:52.038 | at de.hybris.platform.servicelayer.search.internal.resolver.impl.DefaultModelResolver.preloadItems(DefaultModelResolver.java:95) INFO | jvm 1 | main | 2018/10/01 15:35:52.039 | at de.hybris.platform.servicelayer.search.impl.LazyLoadModelList.loadPage(LazyLoadModelList.java:62) INFO | jvm 1 | main | 2018/10/01 15:35:52.039 | at de.hybris.platform.core.LazyLoadItemList.switchPage(LazyLoadItemList.java:216) INFO | jvm 1 | main | 2018/10/01 15:35:52.039 | at de.hybris.platform.core.LazyLoadItemList.switchBufferedPageNoLock(LazyLoadItemList.java:472) INFO | jvm 1 | main | 2018/10/01 15:35:52.039 | at de.hybris.platform.core.LazyLoadItemList.switchBufferedPageSynchronized(LazyLoadItemList.java:464) INFO | jvm 1 | main | 2018/10/01 15:35:52.039 | at de.hybris.platform.core.LazyLoadItemList.switchBufferedPage(LazyLoadItemList.java:459) INFO | jvm 1 | main | 2018/10/01 15:35:52.039 | at de.hybris.platform.core.LazyLoadItemList.getOrSwitchBufferedPage(LazyLoadItemList.java:450) INFO | jvm 1 | main | 2018/10/01 15:35:52.039 | at de.hybris.platform.core.LazyLoadItemList.getOrSwitchBufferedPage(LazyLoadItemList.java:430) INFO | jvm 1 | main | 2018/10/01 15:35:52.039 | at de.hybris.platform.core.LazyLoadItemList.getBuffered(LazyLoadItemList.java:108) INFO | jvm 1 | main | 2018/10/01 15:35:52.051 | at de.hybris.platform.core.LazyLoadItemList.get(LazyLoadItemList.java:94) INFO | jvm 1 | main | 2018/10/01 15:35:52.053 | at java.util.AbstractList$Itr.next(AbstractList.java:358) INFO | jvm 1 | main | 2018/10/01 15:35:52.053 | at de.hybris.platform.core.internal.BaseLazyLoadItemList$1.next(BaseLazyLoadItemList.java:177) INFO | jvm 1 | main | 2018/10/01 15:35:52.053 | at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1042) INFO | jvm 1 | main | 2018/10/01 15:35:52.053 | at com.carrefour.core.cronjob.CarrefourAPICachCronJob.lambda$0(CarrefourAPICachCronJob.java:76) INFO | jvm 1 | main | 2018/10/01 15:35:52.053 | at java.lang.Thread.run(Thread.java:748)
I checked for the above issue in my local, and found that MASTER tenant is ACTIVE. So this error is not relative to my code/requirement. If we use t.run() then we are using thread from hybris itself which I don't want. I want to create my own thread and then I want to execute my code with that thread. So to do this, I need to register my thread into hybris then only hybris will recognize my thread as well in the system.
Any small clue is APPRECIATED. Thanks.
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
To get a properly initialized thread, use de.hybris.platform.core.TenantAwareThreadFactory
Depending on your hybris version, there should be a bean with ID tenantAwareThreadFactory available that you can use to get threads.
If you don't have such a bean, you can easily define it yourself:
<bean id="myThreadFactor" class="de.hybris.platform.core.TenantAwareThreadFactory">
<constructor-arg name="tenant" ref="tenantFactory"/>
</bean>
And a recommendation:
Do not use concurrency primitives like Thread etc directly!
Read "Java Concurrency in Practice" by Brian Goetz, and then build your stuff with the tools available in the java.util.concurrent package, e.g. ExecutorService. It really, really makes your life easier.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please refer https://help.hybris.com/1808/hcd/6a782448755941d5adb22b8e39664a2b.html .
Here are some other links that can be helpful to you:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi - I have raised a question regarding this problem https://answers.sap.com/questions/12771780/how-to-find-the-equivalent-of-links-to-pages-from.html
The new link is https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1808/en-US/6a782448755941d5adb22b8e3966...
Other links that can be useful to you are:
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.