热加载新类

back_recharge
zhangshanxue 2019-10-09 17:03:46 +08:00
parent 5916e26239
commit 2062561e7e
2 changed files with 2 additions and 2 deletions

View File

@ -6,7 +6,6 @@ import java.lang.instrument.Instrumentation;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;
public class JavaAgent {
private static final ThreadLocal<SimpleDateFormat> threadLocal = new ThreadLocal<SimpleDateFormat>();

View File

@ -52,6 +52,7 @@ public class HotfixUtil{
}
LOGGER.debug("HotfixUtil->currVerion={},version={}", currVerion, version);
//TODO 应该只需要instrument 这个可以在应用启动前加 之后直接调用热更新逻辑 不用在运行的过程中动态加载代理
//拿到当前jvm的进程id
String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
VirtualMachine vm = VirtualMachine.attach(pid);
@ -62,7 +63,7 @@ public class HotfixUtil{
List<ClassBean> list = hotfixBean.getClasses();
int i = 0;
for (ClassBean cl : list) {
String path = "../conf/hotswap/"+cl.getName();
String path = "../conf/hotswap/"+cl.getName()+"#"+cl.getFullName();
LOGGER.info("HotfixUtil->i={},path={}", i, path);
vm.loadAgent("../lib/hotfix.jar",path);//path参数即agentmain()方法的第一个参数
i++;