package org.jivesoftware.smack.util;

import java.util.concurrent.ThreadFactory;

public final class SmackExecutorThreadFactory implements ThreadFactory {
   private final int connectionCounterValue;
   private final String name;
   private int count = 0;

   public SmackExecutorThreadFactory(int connectionCounterValue, String name) {
      this.connectionCounterValue = connectionCounterValue;
      this.name = name;
   }

   public Thread newThread(Runnable runnable) {
      Thread thread = new Thread(runnable);
      thread.setName("Smack-" + this.name + ' ' + this.count++ + " (" + this.connectionCounterValue + ")");
      thread.setDaemon(true);
      return thread;
   }
}
