[英]Error while publishing Bean through JMX
I am trying to register a bean on JMX. 我正在尝试在JMX上注册bean。 I am getting error on line
mbs.registerMBean(metadataObj, name);
我在
mbs.registerMBean(metadataObj, name);
行上遇到错误mbs.registerMBean(metadataObj, name);
. 。 Error says
错误说
Multiple markers at this line
- Syntax error on token "(", delete
this token
- Syntax error on token ")", delete
this token
I have no idea what it is about. 我不知道这是怎么回事。
This bean has basic metadata about request start/end time. 该bean具有有关请求开始/结束时间的基本元数据。 Class
类
package test.performance;
public class RequestPerformanceMetadata implements PerformanceMetadataMBean{
private double startTime;
private double endTime;
private double timeTook;
private String requestType;
private int numOfRequests;
PerformanceMetadataMBean metadataObj = new RequestPerformanceMetadata();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("test.performace:type=PerformanceMetadataMBean");
mbs.registerMBean(metadataObj, name);
public double getTimeTook() {
return timeTook;
}
public void setTimeTook(double timeTook) {
this.timeTook = timeTook;
}
Interface 接口
package test.performance;
public interface PerformanceMetadataMBean {
double getTimeTook();
void setTimeTook(double timeTook);
String getRequestType();
void setRequestType(String requestType);
On 上
There's a lot of issues here. 这里有很多问题。
Starting with msb = .... , there's no method.... it needs to be in a method. 从msb = ....开始,没有方法....它必须存在于方法中。 Next, new ObjectName(...) throws an exception, so you need to wrap it in a try/catch block.
接下来, 新的ObjectName(...)引发异常,因此您需要将其包装在try / catch块中。 Also, are you sure you want to create another instance of RequestPerformanceMetadata inside of RequestPerformanceMetadata ?
另外,你确定你想创建RequestPerformanceMetadata 内 RequestPerformanceMetadata的另一个实例? Perhaps you want to simply register the this instance.
也许您只想注册此实例。
Take a look at this code fragment: 看一下这段代码片段:
class RequestPerformanceMetadata implements PerformanceMetadataMBean {
private double startTime;
private double endTime;
private double timeTook;
private String requestType;
private int numOfRequests;
private MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
private ObjectName name;
public RequestPerformanceMetadata() {
try {
name = new ObjectName("test.performace:type=PerformanceMetadataMBean");
mbs.registerMBean(this, name);
} catch (Exception ex) {
throw new RuntimeException("Yo dog. Bad object name", ex);
}
}
//........... snip ...........
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.