登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
1
Star
0
Fork
1
ppnt
/
java-ee-t-io-study
代码
Issues
1
Pull Requests
0
Wiki
统计
流水线
服务
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
t-io-http-server开发环境类动态加载问题
待办的
#I5LYKA
Ping E Lee
拥有者
创建于
2022-08-11 21:41
工程名java-ee-t-io-http-server-3.7.3-hello 什么是开发环境类动态加载 在ide(例如eclipse)中,修改了一个类文件,按Ctrl+S,对该文件的修改会立即生效 开发环境类动态加载是通过重启服务和自定义类加载器来实现 1.在服务启动前开启文件观察期服务,观察文件修改,进行服务重启 2.服务在重启过程中,调用自定义的类加载器,调用加载后的文件 上述两个功能,我都已经开发完成,代码如下 ``` package top.ppnt.java.ee.tio.http.server; import java.text.DecimalFormat; import org.tio.utils.jfinal.P; import com.litongjava.hotswap.debug.Diagnostic; import com.litongjava.hotswap.kit.HotSwapUtils; import com.litongjava.hotswap.server.RestartServer; import com.litongjava.hotswap.watcher.HotSwapWatcher; import lombok.extern.slf4j.Slf4j; import top.ppnt.java.ee.tio.http.server.boot.TioApplication; @Slf4j public class HelloApp { protected static volatile HotSwapWatcher hotSwapWatcher; public static void main(String[] args){ long start = System.currentTimeMillis(); // 加载配置文件 P.use("app.properties"); Boolean isDev = P.getBoolean("dev.mode"); if (isDev) { runDev(HelloApp.class, args); } else { //初始化服务器并启动服务器 TioApplication.run(HelloApp.class,args); } long end = System.currentTimeMillis(); System.out.println("启动完成,共使用了:"+(end-start)+"ms"); } private static void runDev(Class<HelloApp> primarySource, String[] args) { // 获取自定义的classLoalder ClassLoader hotSwapClassLoader = HotSwapUtils.getClassLoader(); log.info("hotSwapClassLoader:{}", hotSwapClassLoader); // 第一次启动不需要使用自定义的类加载器,使用默认的类加载器即可 Thread.currentThread().setContextClassLoader(hotSwapClassLoader); TioApplication.run(primarySource, args); // 需要在spring启动之前启动hotswapWatcher,否则springboot重启之后,hotswapWatcher会也关闭 测试不需要 // 在spring-boot启动之后再启动hotSwapWatcher if (hotSwapWatcher == null) { // 开启热加载调试模式 Diagnostic.setDebug(true); log.info("start hotSwapWatcher"); hotSwapWatcher = new HotSwapWatcher(new RestartServer() { protected DecimalFormat decimalFormat = new DecimalFormat("#.#"); @Override public void restart() { System.err.println("loading"); long start = System.currentTimeMillis(); // 关闭 TioApplication.stop(); // 获取启动类和启动参数 // 获取一个新的ClassLoader ClassLoader hotSwapClassLoader = HotSwapUtils.newClassLoader(); if (Diagnostic.isDebug()) { log.info("new classLoader:{}", hotSwapClassLoader); } // 在启动新的应用之前必须设置上下文加载器 Thread.currentThread().setContextClassLoader(hotSwapClassLoader); // 启动应用 TioApplication.run(HelloApp.class,args); System.err.println("Loading complete in " + getTimeSpent(start) + " seconds (^_^)\n"); } @Override public boolean isStarted() { // boolean running = TioApplication.isRunning(); // log.info("isRunning:{}",running); return true; } protected String getTimeSpent(long startTime) { float timeSpent = (System.currentTimeMillis() - startTime) / 1000F; return decimalFormat.format(timeSpent); } }); hotSwapWatcher.start(); } } } ``` 遇到的问题 服务重启之后controller无法访问,出现的错误日志 ``` 2022-08-11 21:32:42.769 [Thread-20] ERROR TioCallerRunsPolicy.rejectedExecution:212 - ``` 重启前后线程对比 重启前线程数  重启后线程数  很明显 是重启工作没有做到位,请不吝赐教该问题该如何解决 问题复现步骤 1.下载代码 2.导入java-ee-tio-http-server-3.7.3-hello到Eclipse 3.启动top.ppnt.java.ee.tio.http.server.HelloApp 4.访问http://127.0.0.1/hello 获得正确的返回 5.修改Controller文件,按Ctrl+S保存,控制台会提示热加载成功,并显示部分错误日志 6.再次在浏览器重访问接口,显示错误日志
工程名java-ee-t-io-http-server-3.7.3-hello 什么是开发环境类动态加载 在ide(例如eclipse)中,修改了一个类文件,按Ctrl+S,对该文件的修改会立即生效 开发环境类动态加载是通过重启服务和自定义类加载器来实现 1.在服务启动前开启文件观察期服务,观察文件修改,进行服务重启 2.服务在重启过程中,调用自定义的类加载器,调用加载后的文件 上述两个功能,我都已经开发完成,代码如下 ``` package top.ppnt.java.ee.tio.http.server; import java.text.DecimalFormat; import org.tio.utils.jfinal.P; import com.litongjava.hotswap.debug.Diagnostic; import com.litongjava.hotswap.kit.HotSwapUtils; import com.litongjava.hotswap.server.RestartServer; import com.litongjava.hotswap.watcher.HotSwapWatcher; import lombok.extern.slf4j.Slf4j; import top.ppnt.java.ee.tio.http.server.boot.TioApplication; @Slf4j public class HelloApp { protected static volatile HotSwapWatcher hotSwapWatcher; public static void main(String[] args){ long start = System.currentTimeMillis(); // 加载配置文件 P.use("app.properties"); Boolean isDev = P.getBoolean("dev.mode"); if (isDev) { runDev(HelloApp.class, args); } else { //初始化服务器并启动服务器 TioApplication.run(HelloApp.class,args); } long end = System.currentTimeMillis(); System.out.println("启动完成,共使用了:"+(end-start)+"ms"); } private static void runDev(Class<HelloApp> primarySource, String[] args) { // 获取自定义的classLoalder ClassLoader hotSwapClassLoader = HotSwapUtils.getClassLoader(); log.info("hotSwapClassLoader:{}", hotSwapClassLoader); // 第一次启动不需要使用自定义的类加载器,使用默认的类加载器即可 Thread.currentThread().setContextClassLoader(hotSwapClassLoader); TioApplication.run(primarySource, args); // 需要在spring启动之前启动hotswapWatcher,否则springboot重启之后,hotswapWatcher会也关闭 测试不需要 // 在spring-boot启动之后再启动hotSwapWatcher if (hotSwapWatcher == null) { // 开启热加载调试模式 Diagnostic.setDebug(true); log.info("start hotSwapWatcher"); hotSwapWatcher = new HotSwapWatcher(new RestartServer() { protected DecimalFormat decimalFormat = new DecimalFormat("#.#"); @Override public void restart() { System.err.println("loading"); long start = System.currentTimeMillis(); // 关闭 TioApplication.stop(); // 获取启动类和启动参数 // 获取一个新的ClassLoader ClassLoader hotSwapClassLoader = HotSwapUtils.newClassLoader(); if (Diagnostic.isDebug()) { log.info("new classLoader:{}", hotSwapClassLoader); } // 在启动新的应用之前必须设置上下文加载器 Thread.currentThread().setContextClassLoader(hotSwapClassLoader); // 启动应用 TioApplication.run(HelloApp.class,args); System.err.println("Loading complete in " + getTimeSpent(start) + " seconds (^_^)\n"); } @Override public boolean isStarted() { // boolean running = TioApplication.isRunning(); // log.info("isRunning:{}",running); return true; } protected String getTimeSpent(long startTime) { float timeSpent = (System.currentTimeMillis() - startTime) / 1000F; return decimalFormat.format(timeSpent); } }); hotSwapWatcher.start(); } } } ``` 遇到的问题 服务重启之后controller无法访问,出现的错误日志 ``` 2022-08-11 21:32:42.769 [Thread-20] ERROR TioCallerRunsPolicy.rejectedExecution:212 - ``` 重启前后线程对比 重启前线程数  重启后线程数  很明显 是重启工作没有做到位,请不吝赐教该问题该如何解决 问题复现步骤 1.下载代码 2.导入java-ee-tio-http-server-3.7.3-hello到Eclipse 3.启动top.ppnt.java.ee.tio.http.server.HelloApp 4.访问http://127.0.0.1/hello 获得正确的返回 5.修改Controller文件,按Ctrl+S保存,控制台会提示热加载成功,并显示部分错误日志 6.再次在浏览器重访问接口,显示错误日志
评论 (
0
)
登录
后才可以发表评论
状态
待办的
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
未关联
master
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)
1
https://gitee.com/ppnt/java-ee-t-io-study.git
git@gitee.com:ppnt/java-ee-t-io-study.git
ppnt
java-ee-t-io-study
java-ee-t-io-study
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册