<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魔力
    主站蜘蛛池模板: eeuss影院免费92242部| 亚洲Av永久无码精品黑人| 在线播放免费人成毛片乱码| 一本久久综合亚洲鲁鲁五月天| 亚洲aⅴ无码专区在线观看| 四虎免费大片aⅴ入口| 亚洲码欧美码一区二区三区| 成人毛片免费播放| 亚洲av乱码一区二区三区按摩| 成全高清视频免费观看| 看成年女人免费午夜视频| 亚洲 无码 在线 专区| 好湿好大好紧好爽免费视频| 久久久久亚洲AV成人网人人网站| 羞羞视频免费网站在线看| 亚洲国产一成人久久精品| 免费av片在线观看网站| 亚洲国产成人精品久久| 免费黄色网址入口| 二级毛片免费观看全程| 亚洲成AV人片在线观看无码 | 亚洲人成电影福利在线播放 | 国内免费高清在线观看| 亚洲人成自拍网站在线观看| 国产免费资源高清小视频在线观看| 久久水蜜桃亚洲AV无码精品| 亚洲精品线路一在线观看| 日韩视频免费在线观看| 亚洲AV无码乱码在线观看代蜜桃| 日本高清免费不卡视频| 精品多毛少妇人妻AV免费久久| 91亚洲国产成人久久精品网站| 在线免费观看污网站| 国产精品成人69XXX免费视频| 亚洲天堂中文字幕| 在线免费观看一级毛片| 中国好声音第二季免费播放| 亚洲精品国产第1页| 哒哒哒免费视频观看在线www| 男女作爱在线播放免费网站| 亚洲国产欧美国产综合一区|