Class Configurations

java.lang.Object
org.flag4j.concurrency.Configurations

public final class Configurations extends Object

A utility class for configuring standard and concurrent operations.

This class provides configurable settings for multithreaded and blocked computations.

If a configuration file ./configs/GeneralConfigs.properties is present, settings will be loaded at class initialization. If not, default values will be used.

Thread Safety:

This class is designed to be thread-safe.
  • The parallelism setting is managed via ThreadManager, which ensures safe access.
  • The blockSize setting is accessed and modified using synchronized methods.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default block size for blocked algorithms.
    static final int
    The default parallelism (i.e. number of threads) to use for concurrent algorithms.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Gets the current block size used in blocked algorithms.
    static int
    Gets the current parallelism (i.e. number of threads) to be used in concurrent algorithms.
    static void
    Resets all configurations to their default values.
    static void
    setBlockSize(int blockSize)
    Sets the current block size used in blocked algorithms.
    static void
    setParallelismLevel(int parallelismLevel)
    Sets the parallelism level (i.e. number of threads) to use in concurrent algorithms.
    static int
    Sets the parallelism level (i.e. number of threads) for use in concurrent ops as the number of processors available to the Java virtual machine.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_PARALLELISM

      public static final int DEFAULT_PARALLELISM
      The default parallelism (i.e. number of threads) to use for concurrent algorithms.
    • DEFAULT_BLOCK_SIZE

      public static final int DEFAULT_BLOCK_SIZE
      The default block size for blocked algorithms.
      See Also:
  • Method Details

    • setParallelismLevelAsAvailableProcessors

      public static int setParallelismLevelAsAvailableProcessors()
      Sets the parallelism level (i.e. number of threads) for use in concurrent ops as the number of processors available to the Java virtual machine. Note that this value may change during runtime. This method will include logical cores so the value returned may be higher than the number of physical cores on the machine if hyper-threading is enabled.

      Returns:
      The new parallelism value, i.e. the number of available processors.
    • getParallelismLevel

      public static int getParallelismLevel()
      Gets the current parallelism (i.e. number of threads) to be used in concurrent algorithms.
      Returns:
      Current parallelism (i.e. number of threads) to use in concurrent algorithms.
    • setParallelismLevel

      public static void setParallelismLevel(int parallelismLevel)
      Sets the parallelism level (i.e. number of threads) to use in concurrent algorithms.
      Parameters:
      parallelismLevel - The parallelism level (i.e. number of threads) to use in concurrent algorithms.
      • If parallelismLevel > 0: The parallelism level is used as is.
      • If parallelismLevel <= 0: The parallelism level will be set to Math.max(Configurations.DEFAULT_PARALLELISM + parallelismLevel + 1, 1).
    • getBlockSize

      public static int getBlockSize()
      Gets the current block size used in blocked algorithms. If it has not been changed it will default to 64.
      Returns:
      Current block size to use in concurrent algorithms.
    • setBlockSize

      public static void setBlockSize(int blockSize)
      Sets the current block size used in blocked algorithms.
      Parameters:
      blockSize - Block size to be used in concurrent algorithms.
    • resetAll

      public static void resetAll()
      Resets all configurations to their default values.