Springboot Java Application启动脚本,配置
-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=<<port>> -Dcom.sun.management.jmxremote.password.file=<<path>> -Dcom.sun.management.jmxremote.ssl=false
Password file:
controRole #########
monitorRole #########
Spring Application 配置
public class BusinessAspect {
private semaphore;
@Bean(name="semaphorePermitNum")
public Semaphore getSemaphore{
return semaphore;
}
@Around()
pbulic object execute() {
................
semaphore.tryAcquire(1, 10, TimeUnit.MINUTES) {
..................
}
}
}
package com.test;
@Component
@MangeResource(objectName = "com.test:name=RefreshSemaphorePermitMBean")
public class RefreshSemaphorePermitMBean {
@Autowired
@Qualifier("semaphorePermitNum")
private Semaphore semaphorePermitNum;
@MangeAttribute(description = "increase semaphore permit number")
public void setIncreaseSemaphorePermitNum(int permitNum) {
semaphorePermitNum.release(permitNum);
}
}
然后使用Jconsole就可以连接JMX所在的地址和端口