Class Configurations
java.lang.Object
org.flag4j.concurrency.Configurations
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 viaThreadManager
, which ensures safe access. - The
blockSize
setting is accessed and modified using synchronized methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic 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 TypeMethodDescriptionstatic 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
resetAll()
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.
-
Field Details
-
DEFAULT_PARALLELISM
public static final int DEFAULT_PARALLELISMThe default parallelism (i.e. number of threads) to use for concurrent algorithms. -
DEFAULT_BLOCK_SIZE
public static final int DEFAULT_BLOCK_SIZEThe 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 toMath.max(Configurations.DEFAULT_PARALLELISM + parallelismLevel + 1, 1)
.
- If
-
getBlockSize
public static int getBlockSize()Gets the current block size used in blocked algorithms. If it has not been changed it willdefault 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.
-