'Threads are stuck while getting value from spring Configuration class

Name: Optimal_thread_44
State: RUNNABLE
Total blocked: 358 Total waited: 4,252



Stack trace:
[email protected]/java.lang.ThreadLocal.get(ThreadLocal.java:163)
[email protected]/java.util.concurrent.locks.ReentrantReadWriteLock$Sync.tryAcquireShared(ReentrantReadWriteLock.java:487)
[email protected]/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireShared(AbstractQueuedSynchronizer.java:1323)
[email protected]/java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.lock(ReentrantReadWriteLock.java:738)
org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:485)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
com.stackoverflow.config.SomePropertiesClass$$EnhancerBySpringCGLIB$$a9ebbaed.getProperityValue(<generated>)
[email protected]/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[email protected]/java.lang.Thread.run(Thread.java:829)



Name: Optimal_thread_41
State: RUNNABLE
Total blocked: 930 Total waited: 19,510



Stack trace:
[email protected]/java.util.concurrent.locks.ReentrantReadWriteLock$Sync.tryReleaseShared(ReentrantReadWriteLock.java:426)
[email protected]/java.util.concurrent.locks.AbstractQueuedSynchronizer.releaseShared(AbstractQueuedSynchronizer.java:1382)
[email protected]/java.util.concurrent.locks.ReentrantReadWriteLock$ReadLock.unlock(ReentrantReadWriteLock.java:897)
org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:501)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
com.stackoverflow.config.SomePropertiesClass$$EnhancerBySpringCGLIB$$a9ebbaed.getProperityValue(<generated>)
[email protected]/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[email protected]/java.lang.Thread.run(Thread.java:829)

I have a code where I'm passing Autowired configuration class instance to ThreadFactory that is used with ThreadPoolExecutor, and what I saw under load of concurrent calls that some threads are stuck and it seems that there is some deadlock or something in the code at the place were its trying to get some value from the configuration class that was passed. I wanted to know if passing @Autowired classes to threads is safe or how this should be done with Spring.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source