JBoss AS 7.x的確略有不同。
下面是關於「如何在JBoss AS7創建特區」一個漂亮的文章: http://middlewaremagic.com/jboss/?p=366
你可以看到JBoss和您的MBean使用jconsole
,例如JBOSS_HOME/bin/jconsole.sh
並查看MBeans選項卡。我想你的jmx-console.war也會起作用。
看起來你的MBeans沒有被你的應用程序實例化和正確註冊。
有幾種方法可以註冊您的MBean,請參閱上面的文章中的一種可能的方法。
這裏是您可以創建並註冊使用@Singleton,@Startup EJB豆您的MBean另一種方式: - 讓您的MBean @Singleton,@Startup EJB - 在@PostConstruct生命週期方法 註冊您的MBean - 你註銷在@PreDestroy生命週期方法
這裏MBean的跟蹤目前用戶數,用戶的最大數量,性能等爲例的MBean ...
MBean接口,如MonitoringResourceMXBean.java
:
package examples.mymonitoring;
public interface MonitoringResourceMXBean {
// current user count
long getCurrentUsers();
void countUserUp();
void countUserDown();
// maximum user count
long getMaximumUsers();
void setMaximumUsers(long max);
// request count
long getRequests();
long countRequest();
// maximum duration of request
long getMaximumWait();
void reportWait(long wait);
}
MBean實現,例如
package examples.mymonitoring;
import java.lang.management.ManagementFactory;
import java.util.concurrent.atomic.AtomicLong;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.management.MBeanServer;
import javax.management.ObjectName;
@Singleton
@Startup
public class MonitoringResource implements MonitoringResourceMXBean {
private MBeanServer platformMBeanServer;
private ObjectName objectName = null;
private long maximumUsers = 100;
private AtomicLong requestCount = new AtomicLong(0);
private AtomicLong currentUsers = new AtomicLong(0);
private long maximumWait = 0;
@PostConstruct
public void registerInJMX() {
try {
objectName = new ObjectName("MyMonitoring:type=" + this.getClass().getName());
platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
platformMBeanServer.registerMBean(this, objectName);
} catch (Exception e) {
throw new IllegalStateException("Problem during registration of Monitoring into JMX:" + e);
}
}
@PreDestroy
public void unregisterFromJMX() {
try {
platformMBeanServer.unregisterMBean(this.objectName);
} catch (Exception e) {
throw new IllegalStateException("Problem during unregistration of Monitoring into JMX:" + e);
}
}
@Override
public long getCurrentUsers() {
return this.currentUsers.get();
}
@Override
public void countUserUp() {
this.currentUsers.incrementAndGet();
}
@Override
public void countUserDown() {
this.currentUsers.decrementAndGet();
}
@Override
public long getMaximumWait() {
return this.maximumWait;
}
@Override
public long getMaximumUsers() {
return this.maximumUsers;
}
@Override
public void setMaximumUsers(long max) {
this.maximumUsers = max;
}
@Override
public void reportWait(long wait) {
if (wait > maximumWait) maximumWait = wait;
}
@Override
public long getRequests() {
return this.requestCount.get();
}
@Override
public long countRequest() {
return this.requestCount.incrementAndGet();
}
}
希望這個例子有所幫助。
乾杯!