KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javolution > Configuration


1 /*
2  * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
3  * Copyright (C) 2005 - Javolution (http://javolution.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */

9 package javolution;
10
11 import javolution.lang.Reflection;
12
13 /**
14  * This class centralizes <i><b>J</b>avolution</i> configuration parameters.
15  * Applications may change the default values by providing their own
16  * <code>javolution.Configuration</code> class to be loaded in place
17  * of this one (first in classpath) or by modifying this class directly.
18  *
19  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
20  * @version 2.2, January 8, 2004
21  */

22 public final class Configuration {
23
24     /**
25      * Default constructor.
26      */

27     private Configuration() {
28     }
29
30     /**
31      * Returns the maximum number of concurrent thread.
32      *
33      * @return <code>(Number of Processors) - 1</code>
34      * @see javolution.realtime.ConcurrentThread
35      */

36     public static int concurrency() {
37         Reflection.Method availableProcessors = Reflection.getMethod(
38             "java.lang.Runtime.availableProcessors()");
39         if (availableProcessors != null) {
40             Integer processors =
41                 (Integer) availableProcessors.invoke(Runtime.getRuntime());
42             return processors.intValue() - 1;
43         } else {
44             return 0;
45         }
46     }
47
48     /**
49      * Returns the maximum number of object factories.
50      *
51      * @return <code>1024</code>
52      * @see javolution.realtime.ObjectFactory
53      */

54     public static int factories() {
55         return 1024;
56     }
57
58     /**
59      * Indicates if the system hash code is well distributed
60      * (default hashcodes for <code>Object</code> instances).
61      *
62      * @return <code>true</code> if the default system hashcode is not evenly
63      * distributed; <code>false</code> otherwise (small test
64      * performed at start-up).
65      */

66     public static boolean isPoorSystemHash() {
67         return IS_POOR_SYSTEM_HASH;
68     }
69     private static final boolean IS_POOR_SYSTEM_HASH;
70     static {
71         boolean[] dist = new boolean[32]; // Length power of 2.
72
for (int i=0; i < dist.length; i++) {
73             dist[new Object().hashCode() & (dist.length - 1)] = true;
74         }
75         int holes = 0;
76         for (int i=0; i < dist.length; i++) {
77             if (!dist[i]) holes++; // Count holes.
78
}
79         IS_POOR_SYSTEM_HASH = holes > (dist.length >> 1);
80     }
81
82 }
Popular Tags