Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 18th, 2010 | Syntax: Java | Size: 0.67 KB | Hits: 40 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. public void contextInitialized(ServletContextEvent event) {
  2.         List<MemoryPoolMXBean> memoryPools = ManagementFactory.getMemoryPoolMXBeans();
  3.         for (MemoryPoolMXBean memoryPool : memoryPools) {
  4.                 // only set for pools that have usage threshold enabled and are NOT
  5.                 // already set somehow
  6.                 if (memoryPool.isUsageThresholdSupported() && memoryPool.getUsageThreshold() == 0) {
  7.                         MemoryUsage memoryUsage = memoryPool.getUsage();
  8.                         long max = memoryUsage.getMax();
  9.                         String p = System.getProperty("MemoryPoolUsageThresholdPercent", "95");
  10.                         Integer percent = ParseUtil.parseInteger(p);
  11.                         long threshold = max / 100 * percent;
  12.                         memoryPool.setUsageThreshold(threshold);
  13.                 }
  14.         }
  15. }