Springboot和线程问题

时间:2017-10-25 12:04:48

标签: java spring-boot scheduling

我的项目中有一个数据库监听器(DatabaseChangeListener),这是一个线程。我在我的Spring Boot主应用程序中运行这个线程:

@SpringBootApplication
public class PocCamelRoutesManagerBootApplication {

    public static void main(String[] args) {
        SpringApplication.run(PocCamelRoutesManagerBootApplication.class, args);
    }

    @Autowired
    private DataSource dataSource;
    @Autowired
    private RouteRepository routeRepository;  

    @Bean
    public CommandLineRunner schedulingRunner(TaskExecutor executor) {
        return args -> executor.execute(new DatabaseChangeListener(dataSource, routeRepository));
    }

    @Bean
    public TaskExecutor taskExecutor() {
        return new SimpleAsyncTaskExecutor();
    }

}
  • 它运行,但它不再发生变化(它在我使用时起作用 DatabaseChangeListener d = new DatabaseChangeListener(); d.start()),是来自Autowired依赖项吗?
  • 当我取消部署我的应用程序(来自JBoss EAP)时,该线程仍在运行。我要做什么阻止它?

1 个答案:

答案 0 :(得分:0)

您必须在取消部署springboot应用时停止它,在类const Location = new Schema({ floors: [{ type: Schema.Types.ObjectId, ref: 'FloorSchema', }], }); const FloorSchema = new Schema({ stores: [{ type: Schema.Types.ObjectId, ref: 'StoreSchema', }], restrooms: [{ type: Schema.Types.ObjectId, ref: 'RestroomSchema', }], benches: [{ type: Schema.Types.ObjectId, ref: 'BenchSchema', }], }); 中的以下方法中

PocCamelRoutesManagerBootApplication