美文网首页
ResourceBundle定时清除缓冲重新加载配置文件

ResourceBundle定时清除缓冲重新加载配置文件

作者: 隔壁付叔叔 | 来源:发表于2017-06-14 16:35 被阅读0次

    package com.net.util;

    import java.util.Locale;
    import java.util.ResourceBundle;

    public class ResourceTester {
    private final static MyResourceBundleControl ctl = new MyResourceBundleControl();

    /** 
     * @param args 
     * @throws InterruptedException 
     */  
    public static void main(String[] args) throws InterruptedException {  
        System.out.println(getBundle().getString("bao"));  
        Thread.sleep(5000);  
        System.out.println(getBundle().getString("bao"));  
    }  
    
    public static ResourceBundle getBundle() {  
        return ResourceBundle.getBundle("config", Locale.getDefault(), ctl);  
    }  
    
    /** 
     * 重载控制器 
     */  
    private static class MyResourceBundleControl extends ResourceBundle.Control {  
    
        @Override  
        public long getTimeToLive(String baseName, Locale locale) {  
            return 1000;  
        }  
    
        @Override  
        public boolean needsReload(String baseName, Locale locale,  
                String format, ClassLoader loader, ResourceBundle bundle,  
                long loadTime) {  
            return true;  
        }  
    }  
    

    }

    相关文章

      网友评论

          本文标题:ResourceBundle定时清除缓冲重新加载配置文件

          本文链接:https://www.haomeiwen.com/subject/fefeqxtx.html