MapReduce服务 MRS-规则:多线程安全登录方式

时间:2023-11-01 16:19:45

多线程安全登录方式

如果有多线程进行login的操作,当应用程序第一次登录成功后,所有线程再次登录时应该使用relogin的方式。

login的代码样例:

  private Boolean login(Configuration conf){    boolean flag = false;    UserGroupInformation.setConfiguration(conf);        try {      UserGroupInformation.loginUserFromKeytab(conf.get(PRINCIPAL), conf.get(KEYTAB));      System.out.println("UserGroupInformation.isLoginKeytabBased(): " +UserGroupInformation.isLoginKeytabBased());      flag = true;    } catch (IOException e) {      e.printStackTrace();    }    return flag;      }

relogin的代码样例:

public Boolean relogin(){        boolean flag = false;        try {                      UserGroupInformation.getLoginUser().reloginFromKeytab();          System.out.println("UserGroupInformation.isLoginKeytabBased(): " +UserGroupInformation.isLoginKeytabBased());          flag = true;        } catch (IOException e) {            e.printStackTrace();        }        return flag;    }
support.huaweicloud.com/devg3-mrs/mrs_07_450025.html