我需要从ManagedBeans中提取一些指标,并将收集的指标存储在对象bean中。 使用成员变量定义对象bean以保存度量。在这种情况下,扩展ObjectBean并编写提取器类是否正确?
例如:
class ThreadMetricsBean {
private long liveCount, daemonCount;
public void record(long liveCount, long daemonCount) {
this.liveCount = liveCount;
this.daemonCount = daemonCount;
}
}
**// Here to avoid code redundancy I feel it's correct to extend the ThreadMetricsBean class
// Am I wrong ??**
class ThreadMetricsExtractor {
private long liveCount, daemonCount;
public void run() throws Exception{
extractMetrics();
recordToBean();
}
private void collectMetrics() {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
this.liveCount = threadMXBean.getThreadCount();
this.daemonCount = threadMXBean.getDaemonThreadCount();
}
private void recordToBean() {
new ThreadMetricsBean().record(liveCount, daemonCount);
}
}