部分代码如下:
public class Configure {
private static Properties sysProp = new Properties();
private static HashMap sysMap = new HashMap();
private static HashMap inParamMap = new HashMap();
、 private static HashMap outParamMap = new HashMap();
private static Vector funcCodeList = new Vector();
private static HashMap funcNameList = new HashMap();
private static HashMap funcClassList = new HashMap();
private static HashMap funcLogList = new HashMap();
private static HashMap BranchList = new HashMap();
private static HashMap ExchangeList = new HashMap();
private static HashMap KMMSList = new HashMap();
private static HashMap randomImageMap = null;
private static final String TRADE_LOGGER_NAME = "tradelog";
private static final String RUN_LOGGER_NAME = "runlog";
private static Logger tradeLog = null;
private static Logger runLog = null;
static
{
String sysPath = getSysPath();
if (sysPath != null)
sysPath = sysPath.substring(1,sysPath.length());
//System.out.println(sysPath);
try
{
InputStream is = new FileInputStream(sysPath + "/app.properties");
sysProp.load(is);
//String temp = file.getAbsolutePath();
sysMap.put("home.path",sysPath + sysProp.getProperty("home.path"));
//System.out.println("home.path=" + configure.sysMap.get("home.path"));
//temp = file.getAbsolutePath();
sysMap.put("conf.path",sysPath + sysProp.getProperty("conf.path"));
//System.out.println("conf.path=" + configure.sysMap.get("conf.path"));
//处理日志
initLogger();
//从xml中读取系统参数,以及常用信息
readSysXml(sysMap.get("conf.path") + "/sys.xml"); readXml(sysMap.get("conf.path") + "/parameter.xml");
is.close();
}
catch(Exception e)
{
System.out.println(e.toString());
throw new RuntimeException("can not find file app.properties");
}
}
private Configure()
{
System.out.println("--------------------------");
}
private static void initLogger()
{
String fileName = Configure.getProperty("home.path") + "/log4j.properties";
try
{
FileInputStream fis = new FileInputStream(fileName);
Properties p = new Properties();
p.load(fis);
p.setProperty("log4j.appender.A1.File",Configure.getProperty("home.path") + "/" + p.getProperty("log4j.appender.A1.virFile"));
p.setProperty("log4j.appender.A2.File",Configure.getProperty("home.path") + "/" + p.getProperty("log4j.appender.A2.virFile"));
PropertyConfigurator.configure(p);
tradeLog = Logger.getLogger(TRADE_LOGGER_NAME);
runLog = Logger.getLogger(RUN_LOGGER_NAME);
}
catch(Exception e)
{
System.out.println("init Configure error:");
System.out.println(e.toString());
}
}
public static HashMap getRandomImageMap()
{
return randomImageMap;
}
public static void setRandomImageMap(HashMap map)
{
randomImageMap = map;
}
public static String getKMMSList(String id)
{
return (String)KMMSList.get(id);
}
public static HashMap getBranchList()
{
return BranchList;
}
public static HashMap getExchangeList()
{
return ExchangeList;
}
public static Logger getTradeLogger()
{
return tradeLog;
}
public static Logger getRunLogger()
{
return runLog;
}
public static String getSysPath()
{
return new Configure().getClass().getResource("/").getPath();
}
public static String getProperty(String key)
{
return (String)sysMap.get(key);
}
public static String getProperty(String funcCode,String key)
{
return null;
}
public static Vector getFuncCodeList()
{
return funcCodeList;
}
public static HashMap getFuncNameList()
{
return funcNameList;
}
public static HashMap getFuncClassList()
{
return funcClassList;
}
public static String getFuncClassName(String funcCode)
{
return (String)funcClassList.get(funcCode);
}
public static String getFuncLogClassName(String funcCode)
{
return (String)funcLogList.get(funcCode);
}
public static HashMap getFuncInParamList(String funcCode)
{
return (HashMap)inParamMap.get(funcCode);
}
public static Vector getFuncOutParamList(String funcCode)
{
return (Vector)outParamMap.get(funcCode);
}
}
public class Configure {
private static Properties sysProp = new Properties();
private static HashMap sysMap = new HashMap();
private static HashMap inParamMap = new HashMap();
、 private static HashMap outParamMap = new HashMap();
private static Vector funcCodeList = new Vector();
private static HashMap funcNameList = new HashMap();
private static HashMap funcClassList = new HashMap();
private static HashMap funcLogList = new HashMap();
private static HashMap BranchList = new HashMap();
private static HashMap ExchangeList = new HashMap();
private static HashMap KMMSList = new HashMap();
private static HashMap randomImageMap = null;
private static final String TRADE_LOGGER_NAME = "tradelog";
private static final String RUN_LOGGER_NAME = "runlog";
private static Logger tradeLog = null;
private static Logger runLog = null;
static
{
String sysPath = getSysPath();
if (sysPath != null)
sysPath = sysPath.substring(1,sysPath.length());
//System.out.println(sysPath);
try
{
InputStream is = new FileInputStream(sysPath + "/app.properties");
sysProp.load(is);
//String temp = file.getAbsolutePath();
sysMap.put("home.path",sysPath + sysProp.getProperty("home.path"));
//System.out.println("home.path=" + configure.sysMap.get("home.path"));
//temp = file.getAbsolutePath();
sysMap.put("conf.path",sysPath + sysProp.getProperty("conf.path"));
//System.out.println("conf.path=" + configure.sysMap.get("conf.path"));
//处理日志
initLogger();
//从xml中读取系统参数,以及常用信息
readSysXml(sysMap.get("conf.path") + "/sys.xml"); readXml(sysMap.get("conf.path") + "/parameter.xml");
is.close();
}
catch(Exception e)
{
System.out.println(e.toString());
throw new RuntimeException("can not find file app.properties");
}
}
private Configure()
{
System.out.println("--------------------------");
}
private static void initLogger()
{
String fileName = Configure.getProperty("home.path") + "/log4j.properties";
try
{
FileInputStream fis = new FileInputStream(fileName);
Properties p = new Properties();
p.load(fis);
p.setProperty("log4j.appender.A1.File",Configure.getProperty("home.path") + "/" + p.getProperty("log4j.appender.A1.virFile"));
p.setProperty("log4j.appender.A2.File",Configure.getProperty("home.path") + "/" + p.getProperty("log4j.appender.A2.virFile"));
PropertyConfigurator.configure(p);
tradeLog = Logger.getLogger(TRADE_LOGGER_NAME);
runLog = Logger.getLogger(RUN_LOGGER_NAME);
}
catch(Exception e)
{
System.out.println("init Configure error:");
System.out.println(e.toString());
}
}
public static HashMap getRandomImageMap()
{
return randomImageMap;
}
public static void setRandomImageMap(HashMap map)
{
randomImageMap = map;
}
public static String getKMMSList(String id)
{
return (String)KMMSList.get(id);
}
public static HashMap getBranchList()
{
return BranchList;
}
public static HashMap getExchangeList()
{
return ExchangeList;
}
public static Logger getTradeLogger()
{
return tradeLog;
}
public static Logger getRunLogger()
{
return runLog;
}
public static String getSysPath()
{
return new Configure().getClass().getResource("/").getPath();
}
public static String getProperty(String key)
{
return (String)sysMap.get(key);
}
public static String getProperty(String funcCode,String key)
{
return null;
}
public static Vector getFuncCodeList()
{
return funcCodeList;
}
public static HashMap getFuncNameList()
{
return funcNameList;
}
public static HashMap getFuncClassList()
{
return funcClassList;
}
public static String getFuncClassName(String funcCode)
{
return (String)funcClassList.get(funcCode);
}
public static String getFuncLogClassName(String funcCode)
{
return (String)funcLogList.get(funcCode);
}
public static HashMap getFuncInParamList(String funcCode)
{
return (HashMap)inParamMap.get(funcCode);
}
public static Vector getFuncOutParamList(String funcCode)
{
return (Vector)outParamMap.get(funcCode);
}
}
是调用这个类,得到对应的信息现在要得到某个列表
那么就这样调用了HashMap map = Configure.get....List();Iterator it = map.keySet().iterator();
while( ...)
{
....
}
{
return new Configure().getClass().getResource("/").getPath();
}
}
如果有两个地方调用getSysPath()方法..
System.out.println("--------------------------");
你说会打出几条信息
n个地方调用getSysPath()方法
就会打出n条信息
改错了,但是这也是因为问题出现以后才改成这样的,原来是这样的代码public class Configure {
......
private static Configure configure = new Configure();...... public static String getSysPath()
{
return configure.getClass().getResource("/").getPath();
}
...
}但是这样还是会加载2次,这是什么问题?大家帮帮看看