简体   繁体   中英

Autowiring Thread class in spring

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM