@Override
  public void takeLeadership(LeaderElection election) throws Exception {
    if (metastoreTaskThreadPool != null) {
      throw new IllegalStateException("There should be no running tasks before taking the leadership!");
    }
    runningTasks = new ArrayList<>();
    metastoreTaskThreadPool = ThreadPool.initialize(configuration);
    if (!runOnlyRemoteTasks) {
      List<MetastoreTaskThread> alwaysTasks = new ArrayList<>(getAlwaysTasks());
      for (MetastoreTaskThread task : alwaysTasks) {
        task.setConf(configuration);
        task.enforceMutex(election.enforceMutex());
        long freq = task.runFrequency(TimeUnit.MILLISECONDS);
        // For backwards compatibility, since some threads used to be hard coded but only run if
        // frequency was > 0
        if (freq > 0) {
          runningTasks.add(task);
          metastoreTaskThreadPool.getPool().scheduleAtFixedRate(task, freq, freq, TimeUnit.MILLISECONDS);
        }
      }
    } else {
      List<MetastoreTaskThread> remoteOnlyTasks = new ArrayList<>(getRemoteOnlyTasks());
      for (MetastoreTaskThread task : remoteOnlyTasks) {
        task.setConf(configuration);
        task.enforceMutex(election.enforceMutex());
        long freq = task.runFrequency(TimeUnit.MILLISECONDS);
        runningTasks.add(task);
        metastoreTaskThreadPool.getPool().scheduleAtFixedRate(task, freq, freq, TimeUnit.MILLISECONDS);
      }
    }

    runningTasks.forEach(task -> {
      HiveMetaStore.LOG.info("Scheduling for " + task.getClass().getCanonicalName() + " service.");
    });
  }
invoke setConf(Configuration conf) before running
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/leader/HouseKeepingTasks.java