| | 42 | |
| | 43 | |
| | 44 | == 5.counter == |
| | 45 | 使用counter自增可以保证操作的原子性 |
| | 46 | |
| | 47 | |
| | 48 | {{{ |
| | 49 | import java.io.IOException; |
| | 50 | |
| | 51 | import org.apache.hadoop.conf.Configuration; |
| | 52 | import org.apache.hadoop.hbase.HBaseConfiguration; |
| | 53 | import org.apache.hadoop.hbase.client.HTable; |
| | 54 | import org.apache.hadoop.hbase.util.Bytes; |
| | 55 | |
| | 56 | public class test_counter { |
| | 57 | |
| | 58 | public static void main(String[] args) throws IOException { |
| | 59 | |
| | 60 | Configuration conf = null; |
| | 61 | conf = HBaseConfiguration.create(); |
| | 62 | conf.set("hbase.zookeeper.quorum", "192.168.11.64"); |
| | 63 | |
| | 64 | HTable table = new HTable(conf, Bytes.toBytes("test_table")); |
| | 65 | long c = table.incrementColumnValue(Bytes.toBytes("100"), Bytes.toBytes("cf1"), |
| | 66 | Bytes.toBytes("column1"), 4); |
| | 67 | table.close(); |
| | 68 | |
| | 69 | } |
| | 70 | |
| | 71 | } |
| | 72 | }}} |