public boolean scheduleChore(ScheduledChore chore) {
    if (chore == null) {
      return false;
    }
    // always lock chore first to prevent dead lock
    synchronized (chore) {
      synchronized (this) {
        try {
          // Chores should only ever be scheduled with a single ChoreService. If the choreService
          // is changing, cancel any existing schedules of this chore.
          if (chore.getChoreService() == this) {
            LOG.warn("Chore {} has already been scheduled with us", chore);
            return false;
          }
          if (chore.getPeriod() <= 0) {
            LOG.info("Chore {} is disabled because its period is not positive.", chore);
            return false;
          }
          LOG.info("Chore {} is enabled.", chore);
          if (chore.getChoreService() != null) {
            LOG.info("Cancel chore {} from its previous service", chore);
            chore.getChoreService().cancelChore(chore);
          }
          chore.setChoreService(this);
          ScheduledFuture<?> future =
            scheduler.scheduleAtFixedRate(TraceUtil.tracedRunnable(chore, chore.getName()),
              chore.getInitialDelay(), chore.getPeriod(), chore.getTimeUnit());
          scheduledChores.put(chore, future);
          return true;
        } catch (Exception e) {
          LOG.error("Could not successfully schedule chore: {}", chore.getName(), e);
          return false;
        }
      }
    }
  }
Schedule a chore.
@param chore Chore to be scheduled. If the chore is already scheduled with another ChoreService
             instance, that schedule will be cancelled (i.e. a Chore can only ever be scheduled
             with a single ChoreService instance).
@return true when the chore was successfully scheduled. false when the scheduling failed
        (typically occurs when a chore is scheduled during shutdown of service)
hbase-common/src/main/java/org/apache/hadoop/hbase/ChoreService.java