I am trying to create a thread that starts a task set and, if it does not complete within a certain time (for example, 100 seconds), throws an exception. I'm currently trying to do this by encapsulating tasks in a runnable object and using the ExecutorService and Future classes to execute timeouts. However, when I start my web service, I get this exception:
java.util.concurrent.ExecutionException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.localhostInterpolatorHealthCheck': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:202)
I read online that it is not as simple as defining your own threads and running them to start the thread on Spring, so I am wondering how to do this? What am I missing?
java spring multithreading spring-mvc
Evil Washing Machine
source share