<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ivaneeo's blog

    自由的力量,自由的生活。

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
    一. 相同配置(set....)的 Configuration 可以考慮只在整個 Application 中共享同一個實例: 

    Create a configuration instance

    First you have to create a freemarker.template.Configuration instance and adjust its settings. A Configuration instance is a central place to store the application level settings of FreeMarker. Also, it deals with the creation and caching of pre-parsed templates.

    Probably you will do it only once at the beginning of the application (possibly servlet) life-cycle:

    二. 具有不同配置(set....)的 Configuration 應該建立相互獨立的實例:

    From now you should use this single configuration instance. Note however that if a system has multiple independent components that use FreeMarker, then of course they will use their own private Configuration instance.

    三. 共享的 Configuration 實例有利于開啟 MRU Cache 功能:

    Multithreading

    In a multithreaded environment Configuration instances, Template instances and data models should be handled as immutable (read-only) objects. That is, you create and initialize them (for example with set... methods), and then you don't modify them later (e.g. you don't call set...). This allows us to avoid expensive synchronized blocks in a multithreaded environment. Beware with Template instances; when you get a Template instance with Configuration.getTemplate, you may get an instance from the template cache that is already used by other threads, so do not call its set... methods (calling process is of course fine).

    The above restrictions do not apply if you access all objects from the same single thread only.

    四. 開啟 MRU Cache 策略

    Template caching

    FreeMarker caches templates (assuming you use the Configuration methods to create Template objects). This means that when you call getTemplate, FreeMarker not only returns the resulting Template object, but stores it in a cache, so when next time you call getTemplate with the same (or equivalent) path, it just returns the cached Template instance, and will not load and parse the template file again.

    cfg.setCacheStorage(new freemarker.cache.MruCacheStorage(20, 250))  

    Or, since MruCacheStorage is the default cache storage implementation:

    cfg.setSetting(Configuration.CACHE_STORAGE_KEY, "strong:20, soft:250");  

    When you create a new Configuration object, initially it uses an MruCacheStorage where maxStrongSize is 0, and maxSoftSize is Integer.MAX_VALUE (that is, in practice, infinite). But using non-0 maxStrongSize is maybe a better strategy for high load servers, since it seems that, with only softly referenced items, JVM tends to cause just higher resource consumption if the resource consumption was already high, because it constantly throws frequently used templates from the cache, which then have to be re-loaded and and re-parsed.

    五. MRU (Most Recently Used) Cache 自動更新模板內容的特性

    If you change the template file, then FreeMarker will re-load and re-parse the template automatically when you get the template next time. However, since checking if the file has been changed can be time consuming, there is a Configuration level setting called ``update delay''. This is the time that must elapse since the last checking for a newer version of a certain template before FreeMarker will check that again. This is set to 5 seconds by default. If you want to see the changes of templates immediately, set it to 0. Note that some template loaders may have problems with template updating. For example, class-loader based template loaders typically do not notice that you have changed the template file.

    六. MRU Cache 的兩級緩存策略

    A template will be removed from the cache if you call getTemplate and FreeMarker realizes that the template file has been removed meanwhile. Also, if the JVM thinks that it begins to run out of memory, by default it can arbitrarily drop templates from the cache. Furthermore, you can empty the cache manually with the clearTemplateCache method of Configuration.

    The actual strategy of when a cached template should be thrown away is pluggable with the cache_storage setting, by which you can plug any CacheStorage implementation. For most users freemarker.cache.MruCacheStorage will be sufficient. This cache storage implements a two-level Most Recently Used cache. In the first level, items are strongly referenced up to the specified maximum (strongly referenced items can't be dropped by the JVM, as opposed to softly referenced items). When the maximum is exceeded, the least recently used item is moved into the second level cache, where they are softly referenced, up to another specified maximum. The size of the strong and soft parts can be specified with the constructor. For example, set the size of the strong part to 20, and the size of soft part to 250:

    posted on 2011-06-09 15:50 ivaneeo 閱讀(732) 評論(0)  編輯  收藏 所屬分類: java魔力
    主站蜘蛛池模板: 亚洲码一区二区三区| 亚洲国产一级在线观看| 久久亚洲AV无码精品色午夜麻| 一级a性色生活片久久无少妇一级婬片免费放 | 搡女人真爽免费视频大全| 亚洲喷奶水中文字幕电影| 18女人毛片水真多免费| 亚洲国产精品一区二区久| 成人免费视频77777| 精品国产日韩久久亚洲| 黄网址在线永久免费观看 | 日本牲交大片免费观看| youjizz亚洲| 在线免费观看国产视频| 国产成人亚洲精品播放器下载| 国产国产成年年人免费看片| 一区二区三区AV高清免费波多| 在线观看亚洲精品国产| 在线观看免费播放av片| 久久久久亚洲AV无码永不| 在线精品一卡乱码免费| 亚洲精品女同中文字幕| 亚洲国产免费综合| 在线成人精品国产区免费| 亚洲制服丝袜在线播放| 四虎永久免费地址在线网站| 国产乱子伦精品免费视频| 久久亚洲精品人成综合网| 成年男女免费视频网站| 一级毛片a免费播放王色| 色拍自拍亚洲综合图区| 在线视频免费国产成人| 免费无码又爽又刺激一高潮| 亚洲人成免费电影| 亚洲第一区精品日韩在线播放| 午夜精品射精入后重之免费观看 | 亚洲人成网站在线在线观看| 国产亚洲精品免费视频播放| 国产人成免费视频网站| 一边摸一边爽一边叫床免费视频| 精品亚洲aⅴ在线观看|