diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java index 4fa76e5..3761c72 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -132,8 +132,8 @@ public class HTable implements HTableInterface { private ExecutorService pool; // For Multi private boolean closed; private int operationTimeout; - private boolean cleanupPoolOnClose; // shutdown the pool in close() - private boolean cleanupConnectionOnClose; // close the connection in close() + private final boolean cleanupPoolOnClose; // shutdown the pool in close() + private final boolean cleanupConnectionOnClose; // close the connection in close() /** The Async process for puts with autoflush set to false or multiputs */ protected AsyncProcess ap; @@ -183,10 +183,17 @@ public class HTable implements HTableInterface { */ public HTable(Configuration conf, final TableName tableName) throws IOException { - this(tableName, conf == null ? null : HConnectionManager.getConnection(conf), - getDefaultExecutor(conf), conf); - this.cleanupConnectionOnClose = true; - this.cleanupPoolOnClose = true; + this.tableName = tableName; + this.cleanupPoolOnClose = this.cleanupConnectionOnClose = true; + if (conf == null) { + this.connection = null; + return; + } + this.connection = HConnectionManager.getConnection(conf); + this.configuration = conf; + + this.pool = getDefaultExecutor(conf); + this.finishSetup(); } /** @@ -198,8 +205,14 @@ public class HTable implements HTableInterface { * @throws IOException if a remote or network exception occurs */ public HTable(TableName tableName, HConnection connection) throws IOException { - this(tableName, connection, getDefaultExecutor(connection.getConfiguration())); + this.tableName = tableName; this.cleanupPoolOnClose = true; + this.cleanupConnectionOnClose = false; + this.connection = connection; + this.configuration = connection.getConfiguration(); + + this.pool = getDefaultExecutor(this.configuration); + this.finishSetup(); } private static ThreadPoolExecutor getDefaultExecutor(Configuration conf) { @@ -213,10 +226,9 @@ public class HTable implements HTableInterface { // if it is necessary and will grow unbounded. This could be bad but in HCM // we only create as many Runnables as there are region servers. It means // it also scales when new region servers are added. - ThreadPoolExecutor pool = - new ThreadPoolExecutor(1, maxThreads, keepAliveTime, TimeUnit.SECONDS, - new SynchronousQueue(), Threads.newDaemonThreadFactory("htable")); - pool.allowCoreThreadTimeOut(true); + ThreadPoolExecutor pool = new ThreadPoolExecutor(1, maxThreads, keepAliveTime, TimeUnit.SECONDS, + new SynchronousQueue(), Threads.newDaemonThreadFactory("htable")); + ((ThreadPoolExecutor) pool).allowCoreThreadTimeOut(true); return pool; } @@ -251,9 +263,14 @@ public class HTable implements HTableInterface { */ public HTable(Configuration conf, final TableName tableName, final ExecutorService pool) throws IOException { - this(tableName, HConnectionManager.getConnection(conf), pool, conf); + this.connection = HConnectionManager.getConnection(conf); + this.configuration = conf; + this.pool = pool; + this.tableName = tableName; this.cleanupPoolOnClose = false; this.cleanupConnectionOnClose = true; + + this.finishSetup(); } /** @@ -285,30 +302,13 @@ public class HTable implements HTableInterface { */ public HTable(TableName tableName, final HConnection connection, final ExecutorService pool) throws IOException { - this(tableName, connection, pool, connection.getConfiguration()); - } - - /** - * Creates an object to access a HBase table. - * Shares zookeeper connection and other resources with other HTable instances - * created with the same connection instance. - * Use this constructor when the ExecutorService and HConnection instance are - * externally managed. - * @param tableName Name of the table. - * @param connection HConnection to be used. - * @param pool ExecutorService to be used. - * @param conf {@link Configuration} to use for general table properties - * @throws IOException if a remote or network exception occurs - */ - public HTable(TableName tableName, final HConnection connection, final ExecutorService pool, - Configuration conf) throws IOException { if (connection == null || connection.isClosed()) { throw new IllegalArgumentException("Connection is null or closed."); } this.tableName = tableName; this.cleanupPoolOnClose = this.cleanupConnectionOnClose = false; this.connection = connection; - this.configuration = conf; + this.configuration = connection.getConfiguration(); this.pool = pool; this.finishSetup();