简体   繁体   中英

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

I am writing code to access impala using JDBC driver provided by the cloudera . And it works perfectly .

But , I am facing a small problem,..

After closing a connection , when i am checking the connections using netstat -an | grep -i 21050 , I am getting connections are still in Established state until the program exits, when program exits it clears all the Established connections.

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.

Why connections to impalad are still alive even after calling the connection.close(). ???? Am i doing something wrong???

To simulate this please check the below code , where after

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:* LISTEN
tcp 0 0 10.184.43.100:21050 169.144.48.135:52137 ESTABLISHED
root@pasapp ~ #

Thanks !!!

This driver does connection pooling. Your close != the pool's close. No doubt there is some way to configure the pool.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM