<commit_before>/*
 * Copyright 2006-2021 The MZmine Development Team
 *
 * This file is part of MZmine.
 *
 * MZmine is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with MZmine; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

package io.github.mzmine.taskcontrol.impl;

import io.github.mzmine.gui.Desktop;
import io.github.mzmine.gui.HeadLessDesktop;
import io.github.mzmine.gui.preferences.MZminePreferences;
import io.github.mzmine.gui.preferences.NumOfThreadsParameter;
import io.github.mzmine.main.MZmineCore;
import io.github.mzmine.taskcontrol.AbstractTask;
import io.github.mzmine.taskcontrol.Task;
import io.github.mzmine.taskcontrol.TaskControlListener;
import io.github.mzmine.taskcontrol.TaskController;
import io.github.mzmine.taskcontrol.TaskPriority;
import io.github.mzmine.taskcontrol.TaskStatus;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Logger;

/**
 * Task controller implementation
 */
public class TaskControllerImpl implements TaskController, Runnable {

  private Logger logger = Logger.getLogger(this.getClass().getName());

  ArrayList<TaskControlListener> listeners = new ArrayList<TaskControlListener>();

  /**
   * Update the task progress window every 300 ms
   */
  private final int TASKCONTROLLER_THREAD_SLEEP = 300;

  private Thread taskControllerThread;

  private TaskQueue taskQueue;

  /**
   * This vector contains references to all running threads of NORMAL priority. Maximum number of
   * concurrent threads is specified in the preferences dialog.
   */
  private CopyOnWriteArrayList<WorkerThread> runningThreads;

  /**
   * Initialize the task controller
   */
  public void initModule() {

    logger.finest("Starting task controller thread");
    taskQueue = new TaskQueue();

    runningThreads = new CopyOnWriteArrayList<>();

    // Create a low-priority thread that will manage the queue and start
    // worker threads for tasks
    taskControllerThread = new Thread(this, "Task controller thread");
    taskControllerThread.setPriority(Thread.MIN_PRIORITY);
    taskControllerThread.start();

  }

  @Override
  public TaskQueue getTaskQueue() {
    return taskQueue;
  }

  @Override
  public void addTask(Task task) {<commit_msg>Revert "change TaskControllerImpl#runningThreads to CopyOnWriteArrayList"<commit_after>/*
 * Copyright 2006-2021 The MZmine Development Team
 *
 * This file is part of MZmine.
 *
 * MZmine is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with MZmine; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

package io.github.mzmine.taskcontrol.impl;

import io.github.mzmine.gui.Desktop;
import io.github.mzmine.gui.HeadLessDesktop;
import io.github.mzmine.gui.preferences.MZminePreferences;
import io.github.mzmine.gui.preferences.NumOfThreadsParameter;
import io.github.mzmine.main.MZmineCore;
import io.github.mzmine.taskcontrol.AbstractTask;
import io.github.mzmine.taskcontrol.Task;
import io.github.mzmine.taskcontrol.TaskControlListener;
import io.github.mzmine.taskcontrol.TaskController;
import io.github.mzmine.taskcontrol.TaskPriority;
import io.github.mzmine.taskcontrol.TaskStatus;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Logger;

/**
 * Task controller implementation
 */
public class TaskControllerImpl implements TaskController, Runnable {

  private Logger logger = Logger.getLogger(this.getClass().getName());

  ArrayList<TaskControlListener> listeners = new ArrayList<TaskControlListener>();

  /**
   * Update the task progress window every 300 ms
   */
  private final int TASKCONTROLLER_THREAD_SLEEP = 300;

  private Thread taskControllerThread;

  private TaskQueue taskQueue;

  /**
   * This vector contains references to all running threads of NORMAL priority. Maximum number of
   * concurrent threads is specified in the preferences dialog.
   */
  private Vector<WorkerThread> runningThreads;

  /**
   * Initialize the task controller
   */
  public void initModule() {

    logger.finest("Starting task controller thread");
    taskQueue = new TaskQueue();

    runningThreads = new Vector<WorkerThread>();

    // Create a low-priority thread that will manage the queue and start
    // worker threads for tasks
    taskControllerThread = new Thread(this, "Task controller thread");
    taskControllerThread.setPriority(Thread.MIN_PRIORITY);
    taskControllerThread.start();

  }

  @Override
  public TaskQueue getTaskQueue() {
    return taskQueue;
  }

  @Override
  public void addTask(Task task) {
{'fraction_non_alphanumeric': 0.08013876843018214, 'fraction_numerical': 0.009019947961838682, 'mean_word_length': 4.429378531073446, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6273766', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1553, 'n_words': 542}