本地debug的时候,可以实时编译并更新代码,线上也可以不停服来动态更新类,即所说的java热部署。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
public class JavaAgent {
public static final Logger logger = LoggerFactory.getLogger(JavaAgent.class); private static String classesPath; static { // 当前进程pid /** File file = new File(filePath); filePath = file.getAbsolutePath();//得到windows下的正确路径 private static void init() throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { Instrumentation instrumentation = JavaDynAgent.getInstrumentation(); private static void destroy() throws IOException { /** try { public static void main(String[] args) throws Exception { javaAgent(null, new String[] {"com.agileeagle.webgame.framework.util.PortUtil"}); PortUtil.test(); |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
public class JavaDynAgent {
private static Instrumentation instrumentation; private static Object lockObject = new Object(); public JavaDynAgent() { public static void agentmain(String args, Instrumentation inst) { } public static Instrumentation getInstrumentation() { |