<commit_before>package ethanjones.cubes.core.system;

import ethanjones.cubes.side.Side;
import ethanjones.cubes.side.Sided;

public class ThreadPool {

  private final String name;
  private final Runnable runnable;
  private final Thread[] threads;
  private Side side = null;
  private int priority = Thread.NORM_PRIORITY;
  private boolean daemon = false;
  private ThreadGroup group;

  public ThreadPool(String name, Runnable runnable) {
    this(name, runnable, Runtime.getRuntime().availableProcessors());
  }

  public ThreadPool(String name, Runnable runnable, int numThreads) {
    this.name = name;
    this.runnable = runnable;
    this.threads = new Thread[numThreads];
  }

  public ThreadPool setSide(Side side) {
    this.side = side;
    return this;
  }

  public ThreadPool setDaemon(boolean daemon) {
    this.daemon = daemon;
    return this;
  }

  public ThreadPool setPriority(int priority) {
    this.priority = priority;
    return this;
  }

  public ThreadPool start() {
    group = new ThreadGroup(name);
    for (int i = 0; i < threads.length; i++) {
      Thread thread = new Thread(group, new Runnable() {
        @Override
        public void run() {
          if (side != null) Sided.setSide(side);
          runnable.run();
        }
      });
      thread.setDaemon(daemon);
      thread.setPriority(priority);
      thread.setName(name + "-" + (i + 1));
      thread.setUncaughtExceptionHandler(Debug.UncaughtExceptionHandler.instance);
      thread.start();
      threads[i] = thread;
    }
    return this;
  }

  public ThreadPool stop() {
    for (Thread thread : threads) {
      if (thread.isAlive()) {
        thread.interrupt();
      }
    }
    for (Thread thread : threads) {
      if (thread.isAlive()) {
        try {
          thread.join();
        } catch (InterruptedException e) {
          Debug.crash(e);
        }
      }
    }
    return this;
  }
}
<commit_msg>Neater thread creation in ThreadPool<commit_after>package ethanjones.cubes.core.system;

import ethanjones.cubes.side.Side;
import ethanjones.cubes.side.Sided;

public class ThreadPool {

  private final String name;
  private final Runnable runnable;
  private final Thread[] threads;
  private Side side = null;
  private int priority = Thread.NORM_PRIORITY;
  private boolean daemon = false;
  private ThreadGroup group;

  public ThreadPool(String name, Runnable runnable) {
    this(name, runnable, Runtime.getRuntime().availableProcessors());
  }

  public ThreadPool(String name, Runnable runnable, int numThreads) {
    this.name = name;
    this.runnable = runnable;
    this.threads = new Thread[numThreads];
  }

  public ThreadPool setSide(Side side) {
    this.side = side;
    return this;
  }

  public ThreadPool setDaemon(boolean daemon) {
    this.daemon = daemon;
    return this;
  }

  public ThreadPool setPriority(int priority) {
    this.priority = priority;
    return this;
  }

  public ThreadPool start() {
    group = new ThreadGroup(name);
    for (int i = 0; i < threads.length; i++) {
      Thread thread = new Thread(group, name + "-" + (i + 1)) {
        @Override
        public void run() {
          if (side != null) Sided.setSide(side);
          runnable.run();
        }
      };
      thread.setDaemon(daemon);
      thread.setPriority(priority);
      thread.setUncaughtExceptionHandler(Debug.UncaughtExceptionHandler.instance);
      thread.start();
      threads[i] = thread;
    }
    return this;
  }

  public ThreadPool stop() {
    for (Thread thread : threads) {
      if (thread.isAlive()) {
        thread.interrupt();
      }
    }
    for (Thread thread : threads) {
      if (thread.isAlive()) {
        try {
          thread.join();
        } catch (InterruptedException e) {
          Debug.crash(e);
        }
      }
    }
    return this;
  }
}

{'fraction_non_alphanumeric': 0.11021154348393837, 'fraction_numerical': 0.0010446591799425438, 'mean_word_length': 2.6268939393939394, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5931632', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1177, 'n_words': 292}