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

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

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

    ivaneeo's blog

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

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

    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 應(yīng)該建立相互獨(dú)立的實(shí)例:

    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 實(shí)例有利于開(kāi)啟 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.

    四. 開(kāi)啟 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 自動(dòng)更新模板內(nèi)容的特性

    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 的兩級(jí)緩存策略

    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) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): java魔力
    主站蜘蛛池模板: 亚洲男人天堂影院| 亚洲伊人久久综合影院| 亚洲精品免费在线观看| 国产免费A∨在线播放| 亚洲一区精品伊人久久伊人 | 91精品成人免费国产| 亚洲国产婷婷香蕉久久久久久| 亚洲精品无码久久久久久| 久久精品网站免费观看| 日韩亚洲国产综合高清| 成人毛片免费视频| 国产99久久亚洲综合精品| 免费国产一级特黄久久| 四虎成人精品一区二区免费网站| 日本红怡院亚洲红怡院最新| 99ri精品国产亚洲| 久久久久亚洲AV无码永不| 亚洲白嫩在线观看| 丝袜足液精子免费视频| 亚洲VA成无码人在线观看天堂| 日韩精品免费视频| 亚洲国产美女视频| 日本黄色免费观看| 久久久久久噜噜精品免费直播 | 成人无码区免费A片视频WWW| 亚洲一区二区影视| 国产美女被遭强高潮免费网站| 搜日本一区二区三区免费高清视频 | 女人张腿给男人桶视频免费版| 亚洲av无码一区二区三区四区| 全黄a免费一级毛片人人爱| 怡红院免费的全部视频| 亚洲人成网站18禁止久久影院| 国产精品久久免费视频| 青青操在线免费观看| 亚洲w码欧洲s码免费| 亚洲高清偷拍一区二区三区 | 中国人免费观看高清在线观看二区| 久久精品国产亚洲av日韩| 麻豆国产入口在线观看免费| 国产成人高清精品免费观看|