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)加入到 ...
随机推荐
- 0 vs工程添加sdk
配置64位 库目录:(VC++目录) 可选配置 VS SDK(如果报错缺少kernel32.lib) C:\Program Files (x86)\Microsoft SDKs\Windows\v7. ...
- Burp - Attack type
有时间不用难免忘记,做个总结 1. Sniper (狙击手) 它使用一组Payload集合,依次替换Payload位置上(一次攻击只能使用一个Payload位置)被§标志的文本(而没有被§标志的文本将 ...
- Java面试题复习之Java基础
1.面向对象的特征主要有哪些? 封装.继承.多态.抽象 2.final.finally.finalize的区别? final主要用于修饰类.方法.属性(变量)等. 通常被final修饰的类不能够被 ...
- 3150luogu洛谷
若说代码 那真的是很水 但是 思想却有点意思 这道题是洛谷博弈论专题的第一道入门题, 然而刚开始我是不会做的, 毕竟是道入门题, 我博弈论还没入门呢. 这道题的做法就是: 如果m为偶数, 那么先手赢( ...
- python基础学习第一天
def用法 函数定义的基本格式如下: def function(params): somthing return values 说明:return语句可选,出现return语句表示函数 ...
- Ubuntu系统多屏幕时 触摸屏如何分屏定位
有很多的使用我们需要在Ubuntu系统中使用多屏幕的情况,但是有的时候是一个屏幕的触摸屏幕,另一个屏幕是非触摸屏幕,但是问题来了, 有的时候在触摸屏幕上点击的时候竟然在非触摸的响应,这种情况非常不友好 ...
- Android学习之基础知识四-Activity活动1讲
一.活动(Activity)的基本用法: 1.手动创建活动FirstActivity(java源码): A.Android Studio在一个工作区间只允许打开一个项目,点击:File--->C ...
- ingress rewrite
kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/rewrite-target: http://www.oneway.cn ...
- CF487E Tourists 圆方树、树链剖分
传送门 注意到我们需要求的是两点之间所有简单路径中最小值的最小值,那么对于一个点双联通分量来说,如果要经过它,则一定会经过这个点双联通分量里权值最小的点 注意:这里不能缩边双联通分量,样例\(2\)就 ...
- Vue-条件渲染v-if与v-show
一.共同点 根据数据值来判断是否显示DOM元素 二.区别 代码: <!DOCTYPE html> <html lang="en"> <head> ...