<commit_before>//----------------------------------------------------------------------------//
//                                                                            //
//                          O m r E x e c u t o r s                           //
//                                                                            //
//  Copyright (C) <NAME> 2000-2007. All rights reserved.               //
//  This software is released under the GNU General Public License.           //
//  Contact author at <EMAIL> to report bugs & suggestions. //
//----------------------------------------------------------------------------//
//
package omr.util;

import omr.constant.Constant;
import omr.constant.ConstantSet;

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

/**
 * Class <code>OmrExecutors</code> handles the two pools of threads
 * provided to the omr package, each pool containing a number of threads
 * equal to the machine number of processors plus one.
 *
 * @author <NAME>
 * @version $Id$
 */
public class OmrExecutors
{
    //~ Static fields/initializers ---------------------------------------------

    /** Specific application parameters */
    private static final Constants constants = new Constants();

    /** Number of processors available */
    private static final int cpuNb = Runtime.getRuntime()
                                            .availableProcessors() + 10;

    /** Pool with high priority */
    private static volatile Executor highExecutor;

    /** Pool with low priority */
    private static volatile Executor lowExecutor;

    //~ Constructors -----------------------------------------------------------

    /** Not meant to be instantiated */
    private OmrExecutors ()
    {
    }

    //~ Methods ----------------------------------------------------------------

    //-----------------//
    // getHighExecutor //
    //-----------------//
    /**
     * Return the (single) pool of high priority threads
     *
     * @return the high pool, allocated if needed
     */
    public static Executor getHighExecutor ()
    {
        if (highExecutor == null) {
            synchronized (OmrExecutors.class) {
                if (highExecutor == null) {
                    highExecutor = Executors.newFixedThreadPool(
                        cpuNb + 1,
                        new HighFactory());
                }
            }
        }

        return highExecutor;
    }

    //----------------//
    // getLowExecutor //
    //----------------//
    /**
     * Return the (single) pool of low priority threads
     *
     * @return the low pool, allocated if needed
     */
    public static synchronized Executor getLowExecutor ()
    {
        if (lowExecutor == null) {
            synchronized (OmrExecutors.class) {
                if (lowExecutor == null) {
                    lowExecutor = Executors.newFixedThreadPool(
                        cpuNb + 1,
                        new LowFactory());
                }
            }
        }

        return lowExecutor;
    }

    //-----------------//
    // getNumberOfCpus //
    //-----------------//
    /**
     * Report the number of processors available
     *
     * @return the number of CPUs
     */
    public static int getNumberOfCpus ()
    {
        return cpuNb;
    }

    //----------------//
    // useParallelism //
    //----------------//
    /**
     * Report whether we should try to use parallelism as much as possible
     *
     * @return true for parallel
     */
    public static boolean useParallelism ()
    {
        return constants.useParallelism.getValue();
    }

    //~ Inner Classes ----------------------------------------------------------

    //---------//
    // Factory //
    //---------//
    private abstract static class Factory
        implements ThreadFactory
    {
        protected final ThreadGroup group;

        Factory ()
        {
            SecurityManager s = System.getSecurityManager();
            group = (s != null) ? s.getThreadGroup()
                    : Thread.currentThread()
                            .getThreadGroup();
        }

        @Implement(ThreadFactory.class)
        public Thread newThread (Runnable r)
        {
            Thread t = new Thread(group, r, getThreadName(), 0);

            if (t.isDaemon()) {
                t.setDaemon(false);
            }

            return t;
        }

        protected abstract String getThreadName ();
    }

    //-----------//
    // Constants //
    //-----------//
    private static final class Constants
        extends ConstantSet
    {
        Constant.Boolean useParallelism = new Constant.Boolean(
            true,
            "Should we use parallelism when we have several processors?");
    }

    //-------------//
    // HighFactory //
    //-------------//
    private static class HighFactory
        extends Factory
    {
        private final AtomicInteger highThreadNumber = new AtomicInteger(1);

        @Override
        public Thread newThread (Runnable r)
        {
            Thread t = super.newThread(r);

            if (t.getPriority() != Thread.NORM_PRIORITY) {
                t.setPriority(Thread.NORM_PRIORITY);
            }

            return t;
        }

        @Override
        protected String getThreadName ()
        {
            return "high-thread-" + highThreadNumber.getAndIncrement();
        }
    }

    //------------//
    // LowFactory //
    //------------//
    private static class LowFactory
        extends Factory
    {
        private final AtomicInteger lowThreadNumber = new AtomicInteger(1);

        @Override
        public Thread newThread (Runnable r)
        {
            Thread t = super.newThread(r);

            if (t.getPriority() != Thread.MIN_PRIORITY) {
                t.setPriority(Thread.MIN_PRIORITY);
            }

            return t;
        }

        @Override
        protected String getThreadName ()
        {
            return "low-thread-" + lowThreadNumber.getAndIncrement();
        }
    }
}
<commit_msg>Reset CpuNb as a normal value<commit_after>//----------------------------------------------------------------------------//
//                                                                            //
//                          O m r E x e c u t o r s                           //
//                                                                            //
//  Copyright (C) <NAME> 2000-2007. All rights reserved.               //
//  This software is released under the GNU General Public License.           //
//  Contact author at <EMAIL> to report bugs & suggestions. //
//----------------------------------------------------------------------------//
//
package omr.util;

import omr.constant.Constant;
import omr.constant.ConstantSet;

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

/**
 * Class <code>OmrExecutors</code> handles the two pools of threads
 * provided to the omr package, each pool containing a number of threads
 * equal to the machine number of processors plus one.
 *
 * @author <NAME>
 * @version $Id$
 */
public class OmrExecutors
{
    //~ Static fields/initializers ---------------------------------------------

    /** Specific application parameters */
    private static final Constants constants = new Constants();

    /** Number of processors available */
    private static final int cpuNb = Runtime.getRuntime()
                                            .availableProcessors() + 1;

    /** Pool with high priority */
    private static volatile Executor highExecutor;

    /** Pool with low priority */
    private static volatile Executor lowExecutor;

    //~ Constructors -----------------------------------------------------------

    /** Not meant to be instantiated */
    private OmrExecutors ()
    {
    }

    //~ Methods ----------------------------------------------------------------

    //-----------------//
    // getHighExecutor //
    //-----------------//
    /**
     * Return the (single) pool of high priority threads
     *
     * @return the high pool, allocated if needed
     */
    public static Executor getHighExecutor ()
    {
        if (highExecutor == null) {
            synchronized (OmrExecutors.class) {
                if (highExecutor == null) {
                    highExecutor = Executors.newFixedThreadPool(
                        cpuNb + 1,
                        new HighFactory());
                }
            }
        }

        return highExecutor;
    }

    //----------------//
    // getLowExecutor //
    //----------------//
    /**
     * Return the (single) pool of low priority threads
     *
     * @return the low pool, allocated if needed
     */
    public static synchronized Executor getLowExecutor ()
    {
        if (lowExecutor == null) {
            synchronized (OmrExecutors.class) {
                if (lowExecutor == null) {
                    lowExecutor = Executors.newFixedThreadPool(
                        cpuNb + 1,
                        new LowFactory());
                }
            }
        }

        return lowExecutor;
    }

    //-----------------//
    // getNumberOfCpus //
    //-----------------//
    /**
     * Report the number of processors available
     *
     * @return the number of CPUs
     */
    public static int getNumberOfCpus ()
    {
        return cpuNb;
    }

    //----------------//
    // useParallelism //
    //----------------//
    /**
     * Report whether we should try to use parallelism as much as possible
     *
     * @return true for parallel
     */
    public static boolean useParallelism ()
    {
        return constants.useParallelism.getValue();
    }

    //~ Inner Classes ----------------------------------------------------------

    //---------//
    // Factory //
    //---------//
    private abstract static class Factory
        implements ThreadFactory
    {
        protected final ThreadGroup group;

        Factory ()
        {
            SecurityManager s = System.getSecurityManager();
            group = (s != null) ? s.getThreadGroup()
                    : Thread.currentThread()
                            .getThreadGroup();
        }

        @Implement(ThreadFactory.class)
        public Thread newThread (Runnable r)
        {
            Thread t = new Thread(group, r, getThreadName(), 0);

            if (t.isDaemon()) {
                t.setDaemon(false);
            }

            return t;
        }

        protected abstract String getThreadName ();
    }

    //-----------//
    // Constants //
    //-----------//
    private static final class Constants
        extends ConstantSet
    {
        Constant.Boolean useParallelism = new Constant.Boolean(
            true,
            "Should we use parallelism when we have several processors?");
    }

    //-------------//
    // HighFactory //
    //-------------//
    private static class HighFactory
        extends Factory
    {
        private final AtomicInteger highThreadNumber = new AtomicInteger(1);

        @Override
        public Thread newThread (Runnable r)
        {
            Thread t = super.newThread(r);

            if (t.getPriority() != Thread.NORM_PRIORITY) {
                t.setPriority(Thread.NORM_PRIORITY);
            }

            return t;
        }

        @Override
        protected String getThreadName ()
        {
            return "high-thread-" + highThreadNumber.getAndIncrement();
        }
    }

    //------------//
    // LowFactory //
    //------------//
    private static class LowFactory
        extends Factory
    {
        private final AtomicInteger lowThreadNumber = new AtomicInteger(1);

        @Override
        public Thread newThread (Runnable r)
        {
            Thread t = super.newThread(r);

            if (t.getPriority() != Thread.MIN_PRIORITY) {
                t.setPriority(Thread.MIN_PRIORITY);
            }

            return t;
        }

        @Override
        protected String getThreadName ()
        {
            return "low-thread-" + lowThreadNumber.getAndIncrement();
        }
    }
}

{'fraction_non_alphanumeric': 0.18344771901493742, 'fraction_numerical': 0.0023415421881308033, 'mean_word_length': 1.1107702794819359, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5546122', 'n_tokens_mistral': 2938, 'n_tokens_neox': 2812, 'n_words': 787}