HTable is the main class that one would use to interface with HBase table. It allows one to put/get/scan/delete operations on a HBase table. However, it is not thread safe for read nor write.
HTable uses an arrayList writeBuffer to store put actions. As you can see in the doPut mehod, there is no synchronization. If multiple threads make calls to doPut methods, this would result in unexpected value results in your table.
private final ArrayList<Put> writeBuffer = new ArrayList<Put>();
private void doPut(Put put) throws IOException{ validatePut(put); writeBuffer.add(put); currentWriteBufferSize += put.heapSize(); if (currentWriteBufferSize > writeBufferSize) { flushCommits(); } }
Also, HTable has a setting called scannerCaching and is not synchronized in anyway. So the read operation using scan is not thread safe either.
public int getScannerCaching() { return scannerCaching; } public void setScannerCaching(int scannerCaching) { this.scannerCaching = scannerCaching; } public ResultScanner getScanner(final Scan scan) throws IOException { if (scan.getCaching() <= 0) { scan.setCaching(getScannerCaching()); } return new ClientScanner(getConfiguration(), scan, getTableName(), this.connection); }