热部署,未测试
来源:互联网 发布:点卡充值软件 编辑:程序博客网 时间:2024/06/08 11:58
package agent;import java.lang.instrument.Instrumentation;import java.lang.instrument.UnmodifiableClassException;import java.util.Enumeration;import java.util.HashMap;import java.util.LinkedHashSet;import java.util.Map;import java.util.Set;import java.util.jar.JarEntry;import java.util.jar.JarFile;import org.javaRasp.commons.config;public class HotSwap {public static void hotSwap(final Instrumentation inst) {Thread thread = new Thread(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stub// 获取jar包中的class文件加载时间,轮询修改项,实现热加载while (true) {try {Thread.sleep(2000);Class<?>[] loadClasses = LoadClasses.getLoadClasses();if (loadClasses.length > 0) {for (int i = 0; i < loadClasses.length; i++) {System.out.println("[[[[[[[[[[-666-" + loadClasses[i] + "-666-]]]]]]]]]]");}inst.redefineClasses(TransforSysClass.redefineClasses(inst, loadClasses));}} catch (Exception e) {e.printStackTrace();return;}}}});thread.setDaemon(true);thread.start();}}class LoadClasses {// 缓存加载class文件的最后最新修改时间public static Map<String, Long> cacheLastModifyTimeMap = new HashMap<String, Long>();public static Class<?>[] getLoadClasses() {Set<Class<?>> classes = new LinkedHashSet<Class<?>>();JarFile jar;try {jar = new JarFile("E:\\datacloudWorkspace8\\raspHotSwap\\target\\raspHotSwap.jar");Enumeration<JarEntry> entries = jar.entries();// 同样的进行循环迭代while (entries.hasMoreElements()) {JarEntry entry = entries.nextElement();Long currentMillis = entry.getLastModifiedTime().toMillis();String clazzName = entry.getName();// agent/classAdapter/FileAdapter.classif (clazzName.endsWith(".class") && !entry.isDirectory()) {Long cacheTime = cacheLastModifyTimeMap.get(clazzName);if (cacheTime == null) {cacheLastModifyTimeMap.put(clazzName, currentMillis);} else if (!cacheTime.equals(currentMillis)) {cacheLastModifyTimeMap.put(clazzName, currentMillis);System.out.println(clazzName);classes.add(Thread.currentThread().getContextClassLoader().loadClass(clazzName));}}}} catch (Exception e) {e.printStackTrace();}return classes.toArray(new Class[classes.size()]);}}
阅读全文
0 0
- 热部署,未测试
- JAVA热部署测试
- springboot热部署未生效怎么办
- idea2016测试Jrebel热部署测试
- spring-boot下热部署热启动方案测试汇总
- 热部署
- 热部署
- 热部署
- 热部署
- 热部署
- 热部署
- 热部署
- 热部署
- 热部署
- 热部署
- SpringBoot31-springboot开发部署与测试-开发热部署和常规部署
- 热部署和热加载
- liferay 热部署、自动部署
- 冈萨雷斯数字图像处理学习2:视觉基础
- 当需要插入mysql的数据包含单双引号时处理方法
- 顺序表学生个人健康信息表(数组)
- OneinStack中LNMP环境给Nginx开启pathinfo
- 数据结构之单链表——括号匹配
- 热部署,未测试
- STM32 程序如何运行
- RN中,你还在担心怎么传Json文件给服务器?来看看Json内容吧
- 贝叶斯分类器
- Cookie/Session机制详解
- JavaScript HTML DOM常用语法
- ConfigReader(十四)—— ReadGuideHelpConfig
- MySQL系列之源码浅析
- flex AIR读取本地资源