停止在java中以编程方式执行springjdbc查询

yacmzcpb  于 2021-07-16  发布在  Java
关注(0)|答案(1)|浏览(341)

目前,我正在使用JavaSpringJDBC库运行长时间运行的mysql查询。对于这个程序,我需要一种停止正在运行的查询的方法。我想用编程的方式来实现这一点,所以这里不需要终止进程。
另外,使用java代码设置超时和终止线程也不是首选。
有没有一种方法可以使用编程约定来实现这一点,或者有没有更好的方法或设计来用java实现这个用例?

9q78igpj

9q78igpj1#

可以使用sqlkill命令停止进程
样品

MariaDB [(none)]> show processlist;;
+----+-------------+-----------+------+---------+------+--------------------------+-------------------+----------+
| Id | User        | Host      | db   | Command | Time | State                    | Info              | Progress |
+----+-------------+-----------+------+---------+------+--------------------------+-------------------+----------+
|  1 | system user |           | NULL | Daemon  | NULL | InnoDB purge worker      | NULL              |    0.000 |
|  2 | system user |           | NULL | Daemon  | NULL | InnoDB purge worker      | NULL              |    0.000 |
|  3 | system user |           | NULL | Daemon  | NULL | InnoDB purge worker      | NULL              |    0.000 |
|  4 | system user |           | NULL | Daemon  | NULL | InnoDB purge coordinator | NULL              |    0.000 |
|  5 | system user |           | NULL | Daemon  | NULL | InnoDB shutdown handler  | NULL              |    0.000 |
| 46 | root        | localhost | NULL | Query   |   56 | User sleep               | select sleep(199) |    0.000 |
| 47 | root        | localhost | NULL | Query   |    0 | init                     | show processlist  |    0.000 |
+----+-------------+-----------+------+---------+------+--------------------------+-------------------+----------+
7 rows in set (0.00 sec)

MariaDB [(none)]> kill 46;
Query OK, 0 rows affected (0.02 sec)

MariaDB [(none)]> show processlist;;
+----+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
| Id | User        | Host      | db   | Command | Time | State                    | Info             | Progress |
+----+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
|  1 | system user |           | NULL | Daemon  | NULL | InnoDB purge worker      | NULL             |    0.000 |
|  2 | system user |           | NULL | Daemon  | NULL | InnoDB purge worker      | NULL             |    0.000 |
|  3 | system user |           | NULL | Daemon  | NULL | InnoDB purge worker      | NULL             |    0.000 |
|  4 | system user |           | NULL | Daemon  | NULL | InnoDB purge coordinator | NULL             |    0.000 |
|  5 | system user |           | NULL | Daemon  | NULL | InnoDB shutdown handler  | NULL             |    0.000 |
| 47 | root        | localhost | NULL | Query   |    0 | init                     | show processlist |    0.000 |
+----+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
6 rows in set (0.00 sec)

相关问题