Connections to HBase and ZooKeeper are controlled by you with a static HConnectionManager object. This object is a Configuration card (really HBaseConfiguration ) HConnection objects.
HConnectionManager allows you to clear connections for a configuration instance by calling the deleteConnection method.
So, if you want to force close your connections, you can simply add the following line at the end of your code segment:
//free resources and close connections HConnectionManager.deleteConnection(config,true);
But...
The HBase API is designed to multiplex client transactions on a single HConnection, and while multiple HTable instances use the same configuration object, they will use the same HConnection. This saves all connection settings and reduces overhead for repeat transactions.
What does it mean?
This means that whenever possible you really want to limit the number of HBaseConfiguration instances for each process, even if they are distributed across multiple threads. However, keep in mind that the HBaseConfiguration examples are not thread safe , therefore they cannot be modified by multiple threads.
source share