簡體   English   中英

即使在connection.close()調用之后,連接仍處於建立狀態

[英]Connection is in established state even after connection.close() call

我正在編寫代碼,以使用cloudera提供的JDBC驅動程序訪問impala。 而且效果很好。

但是,我面臨一個小問題。

關閉連接后,當我使用netstat -an |檢查連接時 grep -i 21050,直到程序退出之前,我一直處於連接狀態,當程序退出時,它會清除所有已建立的連接。

連接con =
DriverManager.getConnection(“ jdbc:impala://10.184.43.100:21050”);

con.close();

///連接應在此處關閉。 但它沒有在這里關閉

線程。睡眠(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〜#

謝謝 !!!

該驅動程序進行連接池。 您的關閉!=游泳池關閉。 毫無疑問,有一些方法可以配置池。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM