문제

In our java application we have used XMLs to maintain static data and variation conditions. Now these XMLs are growing beyond control. What would be an alternative to maintain our static data and variation conditions which will benefit us in terms of performance cost and usability?

Thanks

도움이 되었습니까?

해결책

For what you said you read the XML file in each request, if you use JAX-B or is getting in as object somehow, after load this files make a Singleton (http://en.wikipedia.org/wiki/Singleton_pattern) to hold this values in memory, this way you will validate the XML just once and will keep it in memory, increasing the performance. But, if the XML is really huge and you can not maintain they in memory, I would suggest putting this information in a database. You could migrate all the data to the database or create a functionality to update the data on system startup according to the XML data. The best solution in this scenario with database would be migrate all data and not use XML anymore. To measure the performance of each approach you would have to write something like:

public static void main(String args[]) {
    Date initialDate = new Date();
    getXmlValue();// or getDBValue();
    Date finalDate = new Date();
    System.out.println("Load XML took " + (initialDate.getTime()-finalDate.getTime()) + "ms");
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top