Updated on 2024-04-29 GMT+08:00

Creating the Configuration Object

Function Description

HBase obtains configuration items by loading a configuration file.

  1. Loading the configuration file is time-consuming. If unnecessary, use the same Configuration object.
  2. Multi-thread synchronization is not considered in the sample code. If necessary, add it by yourself. Other sample codes are the same.

Sample Code

The following code snippets are in the com.huawei.cloudtable.hbase.examples packet.

private static void init() throws IOException {
  // Default load from conf directory
  conf = HBaseConfiguration.create(); // Note [1]
  String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator;
  Path hbaseSite = new Path(userdir + "hbase-site.xml");
  if (new File(hbaseSite.toString()).exists()) {
    conf.addResource(hbaseSite);
  }
}

Precautions

  • Note [1] If the conf directory of the configuration file is added to the classpath path, the code for loading the specified configuration file can be skipped.