Singleton mode read configuration file is created only once

Source: Internet
Author: User

 PackageCom.jy.modules.util;ImportJava.io.InputStream;Importjava.util.Enumeration;ImportJava.util.HashMap;ImportJava.util.Map;Importjava.util.Properties;Importorg.apache.commons.lang.StringUtils;/*** * @description function Description: *@authorAuthor: Zhouzhiwei *@paramParameters: Singleton mode read configuration file only once * @createdate build Date: June 9, 2015 PM 5:55:35 * @projectname project name: CMS * @ Packageclass Package and class name: Com.jy.modules.util.SystemConfigUtil.java*/ Public classSystemconfigutil {Private StaticSystemconfigutil Systemconfigutil =NULL; Private Staticmap<string, string> promap =NewHashmap<string, string>(); @SuppressWarnings ("Rawtypes")    PrivateSystemconfigutil ()throwsException {InputStream is=NULL; Try{Properties Pro=NewProperties (); is= GetClass (). getResourceAsStream ("/filesystem.properties");//by default in the root directoryPro.load (IS); Enumeration e=Pro.propertynames ();  while(E.hasmoreelements ()) {Object Object=(Object) e.nextelement (); String value=(String) Pro.get (object);            Promap.put (String) object, value); }        } Catch(Exception E2) {e2.printstacktrace (); } finally {            Try{is.close (); } Catch(Exception e) {e.printstacktrace (); }        }    }         Public StaticMap<string, string>Getpromap () {returnPromap; }     Public StaticSystemconfigutil getinstance ()throwsException {if(Systemconfigutil = =NULL) {Systemconfigutil=NewSystemconfigutil (); }        return NULL; } @SuppressWarnings ("Static-access")     Public StaticString GetValue (String mapkey)throwsexception{systemconfigutil m=systemconfigutil.getinstance (); Map Map=M.getpromap (); if(Stringutils.isnotblank (Mapkey)) {String key=(String) map.get (Mapkey); returnkey; }        returnMapkey; }            }

Singleton mode read configuration file is created only once

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.