Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
AppFuseSupport




JSPWiki v2.2.33

[RSS]


Hide Menu

HibernateJMX


This is version 5. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]


Here are some instructions for making the Hibernate Statistics JMX MBean available from AppFuse:

The example below has been tested with MX4J 3.0.1, JDK 1.5 Update 2 and Tomcat 5.5.7.

Inside the tomcat startup script, ensure these JAVA_OPTS are set:

JAVA_OPTS=" -Dcom.sun.management.jmxremote.port=9002 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.awt.headless=true"

(Note: Under Windows, I started tomcat5w.exe and set the above properties in the Java tab, in the textfield entitled 'Java Options').

Then, if you are using Spring, add this to your applicationContext-resources.xml file:


    <bean id="jmxExporter"
        class="org.springframework.jmx.export.MBeanExporter">
        <property name="beans">
            <map>
                <entry key="bean:name=myHibernateBean">
                    <ref local="statisticsBean" />
                </entry>
            </map>
        </property>
    </bean> 

    <bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService">
        <property name="statisticsEnabled">
            <value>true</value>
        </property>
    </bean>

Tomcat 5 already contains the MX4J libraries and your AppFuse project should already have the Hibernate libraries in the runtime classpath.

Note: statisticsEnabled does not get set to true properly in the statisticsBean (this is under investigation).

If you are not using Spring, inside StartupListener.java (inside contextInitialized method) add:


import org.hibernate.jmx.*; 
import javax.management.*;
import java.lang.management.ManagementFactory;

try {
    SessionFactory sessionFactory = (SessionFactory)applicationContext.getBean("sessionFactory");
    MBeanServer mbeanServer =
        ManagementFactory.getPlatformMBeanServer();
    ObjectName on =
        new ObjectName("Hibernate:type=statistics,application=appfuse");
    StatisticsService mBean = new StatisticsService()
    mBean.setStatisticsEnabled(true);
    mBean.setSessionFactory(sessionFactory);
    mbeanServer.registerMBean(mBean, on);
}
catch (Exception e) {
    log.error("Error registering Hibernate StatisticsService [" + e.getMessage() "]", e);
}

After starting up AppFuse, you should be able to attach to the server using JConsole (port 9002, as in the config above). From there, you should see the Hibernate MBean where you can view the statistics that have been collected.

How useful is this? Not sure yet! -:)


Attachments:
hibernatestats2.png Info on hibernatestats2.png 27366 bytes
hibernatestats1.png Info on hibernatestats1.png 26678 bytes


Go to top   More info...   Attach file...
This particular version was published on 06-Nov-2006 13:52:47 MST by BenGill.