【发布时间】:2015-08-07 05:27:56
【问题描述】:
我正在编写代码以使用 cloudera 提供的 JDBC 驱动程序访问 impala。而且效果很好。
但是,我遇到了一个小问题,..
关闭连接后,当我使用 netstat -an | 检查连接时grep -i 21050 ,在程序退出之前,我的连接仍处于已建立状态,当程序退出时,它会清除所有已建立的连接。
连接配置 =
DriverManager.getConnection("jdbc:impala://10.184.43.100:21050");con.close();
///连接应该在这里关闭。但这里没有关闭
Thread.sleep(20000);
///此处正在关闭连接。
为什么即使在调用 connection.close() 之后与 impalad 的连接仍然存在。 ???我做错了吗???
要模拟这个,请检查下面的代码,在
之后public class ClouderaJDBCImpalaExample {
// Define a string as the fully qualified class name (FQCN) of
// the desired JDBC driver
static String JDBCDriver = "com.cloudera.impala.jdbc41.Driver";
// Define a string as the connection URL
static String ConnectionURL = "jdbc:impala://10.184.43.100:21050";
static{
try {
// Register the driver using the class name
Class.forName(JDBCDriver);
LogController.logInfoMessage("Impala Driver Loaded.");
}catch(Exception ex)
{
ex.printStackTrace();
System.exit(0);
}
}
public static void main(String[] args) throws InterruptedException {
Connection con = DriverManager.getConnection("jdbc:impala://10.184.43.100:21050");
con.close();
///The connection should close here. But its not closing here
Thread.sleep(20000);
///Connection is closing here.
}
root@pasapp ~ # netstat -an | grep -i 21050
tcp 0 0 0.0.0.0:21050 0.0.0.0:* 听
tcp 0 0 10.184.43.100:21050 169.144.48.135:52137 已建立
root@pasapp ~ #
谢谢!!!
【问题讨论】:
-
此代码无法编译。贴出真实代码。
-
尝试在 close() 前后使用 isClosed() 并检查结果如何
-
很可能驱动程序有一个内部连接池并且不关闭物理连接,只关闭逻辑句柄。然后它可以返回一个连接,而无需进行连接设置。
-
@MarkRotteveel 但是没有设置最大物理连接数限制的api。如果我打开和关闭连接。但在程序运行之前,物理连接仍然存在。
-
我想说您需要联系 Cloudera 以获取更多信息或报告错误。
标签: java jdbc database-connection impala