@Async常见错误

起初在创建定时任务单线程是可用使用私有的修饰方法,后来改成多线程增加注解

@EnableAsync
@Async

启动报错:Need to invoke method ‘task’ found on proxy for target class ,报错原因是因为可能多线程情况下不支持私有的修饰方法,从报错信息来看 应该是task找不到私有的定时任务方法,invoke通过反射获取不到,这样我们只需要改成公开的public就可以了,把private私有的换掉就行

    //把private换成public即可
	public void task2() throws InterruptedException {
	}

参考文献:
1、 https://blog.youkuaiyun.com/qq_28567955/article/details/102601921 20200508
2、 https://stackoverflow.com/questions/50888015/how-to-use-async-with-scheduled-annotation-in-springboot 20200508

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值