创建了一个事件,每5分钟执行一次过程A
现在出现一个情况,事件执行的过程A时间会超过5分钟,
这时到达5分钟的时候,事件会不会又再次执行过程A
导致同时有两个过程A在跑
如果有这种情况,应该怎么避免?有没有相关的配置可以修改?
这个本身就是逻辑问题 事件的执行时间超过了间隔 说明该时间存在特殊情况
方法有很多种 推荐使用 GET_LOCK() 或者在事件中进行异常处理,获取状态中止事件
为了防止多次重复运行,可以做个执行表,对改表进行加锁处理,
If a repeating event does not terminate within its scheduling interval, the result may be multiple instances of the event executing simultaneously. If this is undesirable, you should institute a mechanism to prevent simultaneous instances. For example, you could use the GET_LOCK() function, or row or table locking.
参考
https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html#function_get-lock
https://dev.mysql.com/doc/refman/5.7/en/create-event.html