龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

Java程序的脏数据问题

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
脏数据(Out-of-date data),指过时的数据。 假如在您的Java程序中存在脏数据,将或多或少地给软件系统带来一些问题,如:无法实时地应用已经发生改变的配置,软件系统出现一些莫名其

  脏数据(Out-of-date data),指过时的数据。

  假如在您的Java程序中存在脏数据,将或多或少地给软件系统带来一些问题,如:无法实时地应用已经发生改变的配置,软件系统出现一些莫名其妙的、难以重现的、后果严重的错误等等。尽量避免脏数据的存在是非常有价值的。本文希望能在这方面给同行们一点帮助。

  Fragment 1. 缓存技术的脏数据问题

    /**
      * A report printer is used to print a report.
      *
      * @version 1.0 9/9/2003
      * @author Bill
      */
     public class ReportPrinter {
     /**
         * ConstrUCts a <code>ReportPrinter</code> instance.
     */
        public ReportPrinter() {
           // do something...
     }

     /**
         * Prints a printable.
    *
         * @param printable the specified printable object
     */
        public void print(Printable printable) {
           Graphics g = getGraphics();
           g.setFont(getReportFont(printable.getFont());

           printable.print(g);
     }

     /**
         * Returns the corresponding report font of a java font.
    *
         * @param javaFont the specified java font
         * @return the corresponding report font
     */
       private Font getReportFont(font javaFont) {
           Font reportFont = fontMap.get(javaFont);

           if(reportFont == null) {
             reportFont = loadFont(javaFont);
             fontMap.put(javaFont, reportFont);
        }

           return reportFont;
     }

     /**
        * Loads the corresponding report font of a java font.
    *
         * @param javaFont the specified java font
         * @param the corresponding report font
     */
        protected static Font loadFont(Font javaFont) {
           Font reportFont = null;

  
  

精彩图集

赞助商链接