此内容没有您所选择的语言版本。
19.6. Monitoring performance
Optimization is not much use without monitoring and access to performance numbers. Hibernate provides a full range of figures about its internal operations. Statistics in Hibernate are available per
SessionFactory
.
19.6.1. Monitoring a SessionFactory 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
You can access
SessionFactory
metrics in two ways. Your first option is to call sessionFactory.getStatistics()
and read or display the Statistics
yourself.
Hibernate can also use JMX to publish metrics if you enable the
StatisticsService
MBean. You can enable a single MBean for all your SessionFactory
or one per factory. See the following code for minimalistic configuration examples:
You can activate and deactivate the monitoring for a
SessionFactory
:
- at configuration time, set
hibernate.generate_statistics
tofalse
- at runtime:
sf.getStatistics().setStatisticsEnabled(true)
orhibernateStatsBean.setStatisticsEnabled(true)
Statistics can be reset programmatically using the
clear()
method. A summary can be sent to a logger (info level) using the logSummary()
method.