/*
* Javolution - Java(TM) Solution for Real-Time and Embedded Systems
* Copyright (C) 2005 - Javolution (http://javolution.org/)
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software is
* freely granted, provided that this notice is preserved.
*/
package javolution37.javolution;
import javolution37.javolution.lang.Reflection;
/**
* This class centralizes Javolution configuration parameters.
* Applications may change the default values by providing their own
* javolution.Configuration class to be loaded in place
* of this one (first in classpath) or by modifying this class directly.
*
* @author Jean-Marie Dautelle
* @version 2.2, January 8, 2004
*/
public final class Configuration {
/**
* Default constructor.
*/
private Configuration() {
}
/**
* Returns the maximum number of concurrent thread.
*
* @return (Number of Processors) - 1
* @see javolution37.javolution.realtime.ConcurrentThread
*/
public static int concurrency() {
Reflection.Method availableProcessors = Reflection.getMethod(
"java.lang.Runtime.availableProcessors()");
if (availableProcessors != null) {
Integer processors =
(Integer) availableProcessors.invoke(Runtime.getRuntime());
return processors.intValue() - 1;
} else {
return 0;
}
}
/**
* Returns the maximum number of object factories.
*
* @return 1024
* @see javolution37.javolution.realtime.ObjectFactory
*/
public static int factories() {
return 1024;
}
/**
* Indicates if the system hash code is well distributed
* (default hashcodes for Object instances).
*
* @return true if the default system hashcode is not evenly
* distributed; false otherwise (small test
* performed at start-up).
*/
public static boolean isPoorSystemHash() {
return IS_POOR_SYSTEM_HASH;
}
private static final boolean IS_POOR_SYSTEM_HASH;
static {
boolean[] dist = new boolean[32]; // Length power of 2.
for (int i=0; i < dist.length; i++) {
dist[new Object().hashCode() & (dist.length - 1)] = true;
}
int holes = 0;
for (int i=0; i < dist.length; i++) {
if (!dist[i]) holes++; // Count holes.
}
IS_POOR_SYSTEM_HASH = holes > (dist.length >> 1);
}
}
Ads help maintain this website.