1 9 package javolution; 10 11 import javolution.lang.Reflection; 12 13 22 public final class Configuration { 23 24 27 private Configuration() { 28 } 29 30 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 54 public static int factories() { 55 return 1024; 56 } 57 58 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]; 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++; } 79 IS_POOR_SYSTEM_HASH = holes > (dist.length >> 1); 80 } 81 82 } | Popular Tags |