List<Edge> detectDeadlock() { Collection<Map<String, MapLockState>> collection = (Collection<Map<String, MapLockState>>) callOnAllMembers(new LockInformationCallable()); List<Vertex> graph = new ArrayList<Vertex>(); for (Map<String, MapLockState> mapLockStateMap : collection) { for (MapLockState map : mapLockStateMap.values()) { for (Object key : map.getLockOwners().keySet()) { Vertex owner = new Vertex(map.getLockOwners().get(key)); Vertex requester = new Vertex(map.getLockRequested().get(key)); int index = graph.indexOf(owner); if (index >= 0) { owner = graph.get(index); } else { graph.add(owner); } index = graph.indexOf(requester); if (index >= 0) { requester = graph.get(index); } else { graph.add(requester); } Edge edge = new Edge(); edge.from = requester; edge.to = owner; edge.key = key; edge.mapName = map.getMapName(); edge.globalLock = map.isGlobalLock(); owner.addIncoming(edge); requester.addOutgoing(edge); } } } List<Edge> list = new ArrayList<Edge>(); if (graph != null && graph.size() > 0) { try { graph.get(0).visit(list); } catch (RuntimeException e) { } } return list; }
private void createRuntimeProps(MemberStateImpl memberState) { Runtime runtime = Runtime.getRuntime(); ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); ClassLoadingMXBean clMxBean = ManagementFactory.getClassLoadingMXBean(); MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapMemory = memoryMxBean.getHeapMemoryUsage(); MemoryUsage nonHeapMemory = memoryMxBean.getNonHeapMemoryUsage(); Map<String, Long> map = new HashMap<String, Long>(); map.put( "runtime.availableProcessors", Integer.valueOf(runtime.availableProcessors()).longValue()); map.put("date.startTime", runtimeMxBean.getStartTime()); map.put("seconds.upTime", runtimeMxBean.getUptime()); map.put("memory.maxMemory", runtime.maxMemory()); map.put("memory.freeMemory", runtime.freeMemory()); map.put("memory.totalMemory", runtime.totalMemory()); map.put("memory.heapMemoryMax", heapMemory.getMax()); map.put("memory.heapMemoryUsed", heapMemory.getUsed()); map.put("memory.nonHeapMemoryMax", nonHeapMemory.getMax()); map.put("memory.nonHeapMemoryUsed", nonHeapMemory.getUsed()); map.put("runtime.totalLoadedClassCount", clMxBean.getTotalLoadedClassCount()); map.put( "runtime.loadedClassCount", Integer.valueOf(clMxBean.getLoadedClassCount()).longValue()); map.put("runtime.unloadedClassCount", clMxBean.getUnloadedClassCount()); map.put("runtime.totalStartedThreadCount", threadMxBean.getTotalStartedThreadCount()); map.put("runtime.threadCount", Integer.valueOf(threadMxBean.getThreadCount()).longValue()); map.put( "runtime.peakThreadCount", Integer.valueOf(threadMxBean.getPeakThreadCount()).longValue()); map.put( "runtime.daemonThreadCount", Integer.valueOf(threadMxBean.getDaemonThreadCount()).longValue()); memberState.setRuntimeProps(map); }