People using Hibernate and Sun's JVM usually face the
java.lang.OutOfMemoryError: PermGen space message sooner or later (mostly sooner

). To track down the source of an
OutOfMemoryError problem you've to be able to query the amount of total and free memory within each available memory pool (heap and non-heap pools as well). Here's a short code snippet to demonstrate how to do that ...
String memoryStats = null;
List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
if (memoryPools != null) {
Iterator<MemoryPoolMXBean> memoryPoolIterator = memoryPools.iterator();
while (memoryPoolIterator.hasNext()) {
MemoryPoolMXBean pool = memoryPoolIterator.next();
if (pool != null) {
MemoryUsage usage = pool.getUsage();
if (usage != null) {
memoryStats = (memoryStats != null ? memoryStats + ", " : "") + pool.getName() + " = " + usage.getUsed() + " (" + usage.getMax() + ")";
}
}
}
}
Recent comments
1 day 15 hours ago
1 day 20 hours ago
3 days 3 hours ago
3 days 7 hours ago
3 days 11 hours ago
5 days 9 hours ago
1 week 9 hours ago
1 week 2 days ago
1 week 5 days ago
2 weeks 1 hour ago