Java Configuration Manager Automatic Reloading
公司一个项目的从另外一个小公司,拷贝了一个PropertyParser的类,实现的有问题,必须重启java应用才能读取新的配置。
简单的解决办法,就是每次读任何配置项时,都重新加载xxx.property文件,但是明显不如当年C#的ConfigurationManager好用。
https://stackoverflow.com/questions/20661612/java-equivalent-for-cs-configurationmanager-appsettingsx
这篇文章,只回答了web的,没有针对desktop和console类型的解答。
http://blog.163.com/s_zhchluo/blog/static/15014708200732191454527/
这篇文章提到了 Apache Commons Configuration项目,也解释了其功能原理,很符合我的要求。
https://commons.apache.org/proper/commons-configuration/
The Commons Configuration software library provides a generic configuration interface which enables a Java application to read configuration data from a variety of sources.
望文生义,就是通用的配置库,很不错。
http://commons.apache.org/proper/commons-configuration/userguide_v1.10/howto_filebased.html
节选Automatic Reloading部分的说明:
Automatic Reloading
A common issue with file-based configurations is to handle the reloading of the data file when it changes. This is especially important if you have long running applications and do not want to restart them when a configuration file was updated. Commons Configuration has the concept of so called reloading strategies that can be associated with a file-based configuration. Such a strategy monitors a configuration file and is able to detect changes. A default reloading strategy is FileChangedReloadingStrategy. It can be set on a file-based configuration as follows:
PropertiesConfiguration config = new PropertiesConfiguration("usergui.properties");
config.setReloadingStrategy(new FileChangedReloadingStrategy());
FileChangedReloadingStrategy works as follows: On every property access the configuration checks its associated reloading strategy. FileChangedReloadingStrategy will then obtain the last modification date of the configuration file and check whether it has changed since the last access. If this is the case, a reload is triggered. To avoid often disk access when multiple properties are queried from the configuration, a refresh delay can be set on the reloading strategy. This is a time in milli seconds with the meaning that the reloading strategy will only once check the file's last modification time in the period specified here.
每一次属性访问时,都会检查文件,如果最后访问时间有变化,则自动重新载入。为了减少硬盘访问频率,又添加了"刷新延迟(设定刷新延迟时间)"机制。上述机制基于commons-configuration/userguide_v1.10。
还有一篇介绍如何实现重载机制的文章,讲解了其他重载机制。
https://commons.apache.org/proper/commons-configuration/userguide/howto_reloading.html
Java Configuration Manager Automatic Reloading的更多相关文章
- Oracle's Business Intelligence Applications Configuration Manager 基本概念
Oracle's Business Intelligence Applications Configuration Manager :BIACM Once the BIAPPS installatio ...
- Spring Security(十二):5. Java Configuration
General support for Java Configuration was added to Spring Framework in Spring 3.1. Since Spring Sec ...
- Windows 8上使用SQL 2012 Configuration Manager
现在使用Windows 8 + Sql Server 2012,而今天想用SQL 2012 Configuraton Manager, 设置别名来访问不同的开发数据库.但发现没能找到SQL 2012 ...
- SQL Server Configuration Manager出错
在 Windows 桌面上,单击“开始”,然后单击“运行”. 在“打开”框中,键入 MMC,然后单击“确定”. 在“控制台”窗口中,单击菜单栏上的“文件”,然后单击“添加/删除管理单元”. 在“ ...
- Sql Server Configuration Manager 网络配置为空,没有实例
新用户一天内不准提问...Sql Server Configuration Manager 网络配置为空,没有实例无法设置ip和端口进行连接..
- Configuration Manager 和内容位置(包源文件)
Configuration Manager 2007 中的内容位置涉及 Configuration Manager 2007 客户端如何查找播发和软件更新的包源文件.当客户端需要查找内容时,它会将内容 ...
- Mybatis Spring multiple databases Java configuration
https://stackoverflow.com/questions/18201075/mybatis-spring-multiple-databases-java-configuration ** ...
- SQL SERVER – Configuration Manager – Cannot Connect to WMI Provider. You Do Not Have Permission or The Server is Unreachable
打开SQL SERVER Configuarion Manger 出现以下错误 SQL Server Configuration Manager—————————Cannot connect to W ...
- System Center Configuration Manager 2016 配置安装篇(Part3)
SCCM 2016 配置管理系列(Part 1- 4) 介绍AD01上配置了Active Directory域服务(ADDS),然后将Configuration Manager服务器(CM16)加入到 ...
随机推荐
- Js 不支持函数的重载
Js 不支持函数的重载,可以用相同的名字在同一作用区域,定义两个函数,而不会引起错误,但真正使用的是最后一个. Js 不会验证传递给函数的参数个数是否和函数定义的参数的个数相同,开发人员定义的函数都可 ...
- DIYer最担心的事来了!CPU降价彻底无望
12月27日,IDC发布2019年中国PC市场十大预测.IDC指出,2018年全年中国PC市场预计最终销售为5200万台左右,下滑了3.4%.2019年中国PC市场会处于一种习惯性艰难期,但是市场也不 ...
- webview与JS的交互
webview与JS的交互 一:hybird app, web app 和 native app 的区别 Web App Hybird App 混合Native App 开发成本 低 中 高 维护 ...
- QT显示url图片
QT 显示网络图片我目前的办法就是先下载下来 然后显示 如果有好的办法请相互交流一下 需要调用的头文件 #include <QNetworkAccessManager> #include ...
- React-本地状态(state)
在类组件中添加本地状态(state): 1.创建一个继承自 React.Component 类的 ES6 class 同名类: 2.添加一个 类构造函数(class constructor) 初始化 ...
- Vue-认识状态管理vuex
vuex是一个专门为vue.js设计的状态管理模式,并且也可以使用devtools进行调试,可以多个组件共享状态.简单来说,就是共享的状态用state来存放,用mutations来操作state,但是 ...
- zookeepeer使用zkCli.sh命令
一.连接服务器端 [root@sxl132 zookeepeer]# ./bin/zkCli. Connecting to -- ::, [myid:] - INFO [main:Environmen ...
- cp 命令有坑
cp 是个很常用的命令, 基本语法为 cp -v a b 把文件a 复制为文件b(-v为显示做了什么,这是非常安全的做法,建议新手添加此参数) 参数说明: -a:此选项通常在复制目录时使用, ...
- STM32串口打印输出乱码的解决办法
前言 最近在试用uFUN开发板,下载配套的Demo程序,串口数据输出正常,当使用另一个模板工程,调用串口printf调试功能时,输出的却是乱码,最后发现是外部晶振频率不一样.很多STM32开发板都是使 ...
- 使用 cron 定时任务实现 war 自动化发布
autoRelease.sh #!/bin/sh /home/tomcat/bin/shutdown.sh echo "tomcat stoped" cd /home/tomcat ...