@SuppressWarnings("unchecked")
  public static <T> T getInstance(Class<T> klass) {
    synchronized (SingletonStorage.INSTANCE.lock) {
      T instance = (T) SingletonStorage.INSTANCE.instances.get(klass);
      if (instance == null) {
        try {
          ServiceLoader<T> loader = ServiceLoader.load(klass);
          Iterator<T> it = loader.iterator();
          instance = it.next();
          if (it.hasNext()) {
            StringBuilder msg = new StringBuilder();
            msg.append("ServiceLoader provided more than one implementation for class: ")
              .append(klass).append(", using implementation: ").append(instance.getClass())
              .append(", other implementations: {");
            while (it.hasNext()) {
              msg.append(it.next()).append(" ");
            }
            msg.append("}");
            LOG.warn(msg.toString());
          }
        } catch (Exception e) {
          throw new RuntimeException(createExceptionString(klass), e);
        } catch (Error e) {
          throw new RuntimeException(createExceptionString(klass), e);
        }

        // If there was nothing returned and no exception then throw an exception.
        if (instance == null) {
          throw new RuntimeException(createExceptionString(klass));
        }
        SingletonStorage.INSTANCE.instances.put(klass, instance);
      }
      return instance;
    }

  }
Get the singleton instance of Any classes defined by compatibiliy jar's
@return the singleton
hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/CompatibilitySingletonFactory.java