Project

General

Profile

« Previous | Next » 

Revision 857df1fc

Added by Andreas Kohlbecker about 11 years ago

avoid uneccesary logging

View differences:

src/main/java/eu/etaxonomy/cdm/server/JvmManager.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
23 23
 *
24 24
 */
25 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 26

  
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
		}
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.debug("NonHeapMemoryUsage: "+memoryMXBean.getHeapMemoryUsage());
59
                return memoryMXBean.getHeapMemoryUsage();
60
            }
61
            return null;
62
        }
63 63

  
64 64
}

Also available in: Unified diff