java - 如何中断使用 Postgresql 运行 JDBC 查询的线程?

标签 java multithreading postgresql jdbc

我有一个运行任务的线程池,主要使用 JDBC 查询 Postgresql。如果取消已提交任务的 future 会取消任何正在进行的查询,那将很方便。是否有捷径可寻?它只适用于 Postgresql。

最佳答案

你可以使用 Statement.cancel() :

Cancels this Statement object if both the DBMS and driver support aborting an SQL statement. This method can be used by one thread to cancel a statement that is being executed by another thread.

cancel() 在 PostgreSQL JDBC 驱动程序中实现(s. PgStatement)

关于java - 如何中断使用 Postgresql 运行 JDBC 查询的线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45184787/

相关文章:

java - get-put原理的解释

python - 必须使用 y 实例作为第一个参数调用未绑定(bind)方法 x() (改为使用 int 实例)

c - 为什么我的 UDS 服务器不接受连接?

PostgreSQL - JSONB 列的 GROUP_CONCAT

python - 如何将 numpy 字符串数组(带逗号)保存到 CSV?

sql - A喜欢B,B不喜欢A?

java - 在没有 View 解析器的情况下重定向到 spring-boot-starter-webflux 中的外部绝对 URL

java - MySql 数据在第 1 行的 'advance' 列被截断

java - 使用 Java 'File' 类访问 GCS 中存在的文件

c# - 多线程列表模式建议