class CountedThreadFactory implements ThreadFactory {

  @Override
  public Thread newThread(@NotNull Runnable runnable) {

    Thread thread =
        delegate.newThread(
            () -> {
              running.incrementAndGet();
              try {
                runnable.run();
              } finally {
                running.decrementAndGet();
                terminated.increment();
              }
            });
    created.increment();
    return thread;
  }

  public  CountedThreadFactory(
      ThreadFactory delegate, MeterRegistry registry, String name, Iterable<Tag> tags);

}