Project

General

Profile

Download (1.87 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.server;
11

    
12
import java.lang.management.ManagementFactory;
13
import java.lang.management.MemoryMXBean;
14
import java.lang.management.MemoryPoolMXBean;
15
import java.lang.management.MemoryUsage;
16
import java.util.List;
17

    
18
import org.apache.log4j.Logger;
19

    
20
/**
21
 * @author a.kohlbecker
22
 * @date 30.07.2010
23
 *
24
 */
25
public class JvmManager {
26
	
27
	/**
28
	 * 
29
	 */
30
	private static final String SUFFIX_PERM_GEN = "Perm Gen";
31
	
32
	public static final Logger logger = Logger.getLogger(JvmManager.class);
33
	
34
	public static MemoryUsage getPermGenSpaceUsage(){
35
		return getMemoryPoolUsage(SUFFIX_PERM_GEN);
36
	}
37

    
38
	protected static MemoryUsage getMemoryPoolUsage(String nameSuffix) {
39
		List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
40
    	
41
    	for(MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans){
42
			if(memoryPoolMXBean.getName().endsWith(nameSuffix)){
43
    			logger.debug(memoryPoolMXBean.getName() 
44
    					+ ": init= " + memoryPoolMXBean.getUsage().getInit()
45
    					+ ", used= "+memoryPoolMXBean.getUsage().getUsed()
46
    					+ ", max= "+memoryPoolMXBean.getUsage().getMax()
47
    					+ ", committed= "+memoryPoolMXBean.getUsage().getCommitted());
48
    			return memoryPoolMXBean.getUsage(); 
49
    		}
50
    	}
51
    	return null;
52
	}
53
	
54
	public static MemoryUsage getHeapMemoryUsage(){
55
			
56
			MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
57
	    	if(memoryMXBean != null){
58
	    		logger.info("NonHeapMemoryUsage: "+memoryMXBean.getHeapMemoryUsage());
59
	    		return memoryMXBean.getHeapMemoryUsage();
60
	    	}
61
	    	return null;
62
		}
63

    
64
}
(5-5/5)