All Downloads are FREE. Search and download functionalities are using the official Maven repository.

prng.collector.DaemonThreadFactory Maven / Gradle / Ivy

There is a newer version: 0.7
Show newest version
package prng.collector;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * A creator of daemon threads for the PRNG background processes.
 *
 * @author Simon
 */
public class DaemonThreadFactory implements ThreadFactory {

  /** Thread name prefix */
  private final String name;

  /** Generator for unique ID numbers for the threads */
  private final AtomicInteger idSrc = new AtomicInteger();


  /**
   * Create a new factory
   *
   * @param name the name prefix for threads
   */
  public DaemonThreadFactory(String name) {
    this.name = name;
  }


  @Override
  public Thread newThread(Runnable r) {
    Thread thread = new Thread(r, name + "-" + idSrc.incrementAndGet());
    thread.setDaemon(true);
    return thread;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy