I have Constants class in my web application.
I want to monitor Constants
class using Jconsole
.
I have @ManagedResource
used annotation for Constants class and @ManagedAttribute
for setter method.
If I will use @ManagedAttribute
for static method then it will not displayed in Jconsole
and for non-static method it works fine.
Can you please provide explanation why it was not working with static method?
Following is my Constants class.
@ManagedResource(
objectName = "Sample:name=ActivityQueueUtil",
description = "Allows modifying all settings."
)
public class ActivityQueueUtil {
private static volatile ActivityQueueUtil instance;
public static ActivityQueueUtil getInstance() {
if (instance == null ) {
synchronized (Constants.class) {
if (instance == null) {
instance = new ActivityQueueUtil();
}
}
}
return instance;
}
public void initInstance() {
instance = this;
}
private int currentWorkerCount = 0;
private int currentQueueSize = 0;
private int currentRetryQueueSize = 0;
@ManagedAttribute(description = "Current number of worker threads.")
public static int getCurrentWorkerCount() {
return currentWorkerCount;
}
public void setCurrentWorkerCount(int currentWorkerCount) {
this.currentWorkerCount = currentWorkerCount;
}
@ManagedAttribute(description = "Number of activities in the queue")
public int getCurrentQueueSize() {
return currentQueueSize;
}
}
Here it works for setCurrentWorkerCount,getCurrentQueueSize
but not working for getCurrentWorkerCount