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

时间: 2024-11-09 08:50:38

Java Configuration Manager Automatic Reloading的相关文章

Oracle's Business Intelligence Applications Configuration Manager 基本概念

Oracle's Business Intelligence Applications Configuration Manager :BIACM Once the BIAPPS installation is completed, the newly introduced web-based JAVA applications, BI Configuration Manager (BIACM) and Functional Set-up Manager (FSM), are available

Oracle's Business Intelligence Applications Configuration Manager 基本概念

Oracle's Business Intelligence Applications Configuration Manager :BIACM Once the BIAPPS installation is completed, the newly introduced web-based JAVA applications, BI Configuration Manager (BIACM) and Functional Set-up Manager (FSM), are available

Spring Security(十二):5. Java Configuration

General support for Java Configuration was added to Spring Framework in Spring 3.1. Since Spring Security 3.2 there has been Spring Security Java Configuration support which enables users to easily configure Spring Security without the use of any XML

System Center 2012 R2 CM系列之配置configuration manager防火墙设置

为了能够正常推送Configuration Manager 2012 R2客户端,必须添加防火墙例外设置,主要包括以下两个:A:文件和打印共享:B: Windows Management Instrumentation (WMI) 1. 打开并登录"BJ-DC-01"服务器,点击工具,打开组策略管理器 2. 右键相关域,点击创建"在这个域中创建GPO并在此处链接" 3. 新建GPO对话框中输入相应的GPO名称 4. 右键新创建的PGO,点击编辑,并打开组策略管理编辑

System Center Configuration Manager,Version1606 部署手册

1. 环境描述 活动目录服务器 计算机名:SH-DC-01 所在域名或工作组名称:365vCloud.net IP地址:192.168.100.2/24 操作系统:Windows Server 2016 中文标准版 已安装角色:ADDS活动目录服务 SCCM中心站点服务器(CAS) 计算机名:SH-SCCM-01 所在域名或工作组名称:365vCloud.net IP地址:192.168.100.4/24 操作系统:Windows Server 2016 中文标准版 已安装角色:无 SCCM主站

System Center 2012 R2 CM系列之安装Configuration Manager预装软件

安装Configuration Manager 2012 R2 预装软件 本章节主要描述创建Configuration Manager 2012 R2所必须的system container.设计Configuration Manager 2012 R2服务器权限.扩展Active Directory架构以及安装安装Configuration Manager 2012 R2所必须的服务器角色和功能 1. 创建系统管理对象 1) 使用管理员账户登陆"BJ-DC-01" 2) 点击服务器管

【补发】安装Configuration Manager 2012 R2 预装软件

由于之前发布SCCM博客时,漏发该章节,故在此补发. 本章节主要描述创建Configuration Manager 2012 R2所必须的system container.设计Configuration Manager 2012 R2服务器权限.扩展Active Directory架构以及安装安装Configuration Manager 2012 R2所必须的服务器角色和功能 1. 创建系统管理对象 1) 使用管理员账户登陆"BJ-DC-01" 2) 点击服务器管理器,点击ADSI编

使用Configuration Manager部署及管理软件更新(1)

今天为大家演示使用Configuration Manager部署及管理软件更新. 一. 技术概述 1. 软件更新同步 Configuration Manager 中的软件更新同步使用 Microsoft 更新来检索软件更新元数据.顶层站点(管理中心站点或独立主站点)按计划或在企业中从 Configuration Manager 控制台中手动启动同步时与 Microsoft 更新同步. 当 Configuration Manager 在顶层站点上完成软件更新同步时,软件更新同步将在子站点(如果存在

System Center 2012 R2 POC部署之Configuration Manager部署

System Center 2012 R2 POC部署之Configuration Manager部署 一.准备工作 1. 安装IIS..NET 打开添加角色和向导,点击下一步 选择基于角色或基于功能的安装,点击下一步 选择服务器 勾选Web服务器(IIS).Windows Server更新服务.Windows部署服务 点击下一步,勾选.NET 3.5.后天职能传输服务 输入存储更新的路径 点击下一步 勾选部署服务器.传输服务器,点击下一步 勾选相关的服务,点击下一步 点击指定备用路径,添加备用