开发者

Autowiring Thread class in spring

开发者 https://www.devze.com 2023-02-14 05:31 出处:网络
Is it possible to autowire a Thread class in spring like controller, Service? If yes what annotation shall I use to开发者_运维知识库 autowire such a class?Depending on what you are doing, I would cons

Is it possible to autowire a Thread class in spring like controller, Service? If yes what annotation shall I use to开发者_运维知识库 autowire such a class?


Depending on what you are doing, I would consider using TaskExecutors instead of directly creating threads. This way thread lifecycle, pooling etc. is managed through the TaskExecutor.

See http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html


Every Thread accepts an implementation of Runnable interface in its constructor. Inject all the dependencies in the implementation and then use an ExecutorService to run it.

0

精彩评论

暂无评论...
验证码 换一张
取 消