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

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

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

    李李的技術(shù)博客

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      13 隨筆 :: 0 文章 :: 61 評論 :: 0 Trackbacks
    很容易找到getText實(shí)際的操作類是LocalizedTextUtil,方法public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack);

    java doc 如下

    Finds a localized text message for the given key, aTextName. Both the key and the message itself is evaluated as required. The following algorithm is used to find the requested message:

    1. Look for message in aClass' class hierarchy.
      1. Look for the message in a resource bundle for aClass
      2. If not found, look for the message in a resource bundle for any implemented interface
      3. If not found, traverse up the Class' hierarchy and repeat from the first sub-step
    2. If not found and aClass is a ModelDriven Action, then look for message in the model's class hierarchy (repeat sub-steps listed above).
    3. If not found, look for message in child property. This is determined by evaluating the message key as an OGNL expression. For example, if the key is user.address.state, then it will attempt to see if "user" can be resolved into an object. If so, repeat the entire process fromthe beginning with the object's class as aClass and "address.state" as the message key.
    4. If not found, look for the message in aClass' package hierarchy.
    5. If still not found, look for the message in the default resource bundles.
    6. Return defaultMessage

    主要就是查找resource bundle,下面說明一下
    1. 先查找該class(一般我們是在action調(diào)用,就是該action對應(yīng)的class了)對應(yīng)的properties文件,找不到再去找對應(yīng)的接口,找不到再去從該class的繼承樹上去重復(fù)前面的步驟。
    2. 如果是ModelDriver,以上找不到再以model的class去重復(fù)1的步驟
    3.繼續(xù)找,如果key是符合ognl表達(dá)式還以ognl表達(dá)式去解析類,如果能找到類,還以以上的步驟去查找
    4. 還找不到,就從根據(jù)package以及package的繼承樹去找,這還包括了該class的繼承樹所有的class的package樹(這一步存在了太多的重復(fù)查找工作,因?yàn)楹芏鄍ackage都是相同的)
    5 使用默認(rèn)的resource bundle

    java.util.ResourceBundle雖然有cache,但是ww為了減少調(diào)用getResourceBundle方法,也維護(hù)了一個miss的hashset,找不到的bundle name就丟進(jìn)去,那么每一次查找都同步了這個miss,如果很多次查找,開銷也是很大的。

    我就舉一個例子,就說第四步查找package樹好了

            // nothing still? alright, search the package hierarchy now
            for (Class clazz = aClass;
                 (clazz 
    != null&& !clazz.equals(Object.class);
                 clazz 
    = clazz.getSuperclass()) {

                String basePackageName 
    = clazz.getName();
                
    while (basePackageName.lastIndexOf('.'!= -1) {
                    basePackageName 
    = basePackageName.substring(0, basePackageName.lastIndexOf('.'));
                    String packageName 
    = basePackageName + ".package";
                    msg 
    = getMessage(packageName, locale, aTextName, valueStack, args);

                    
    if (msg != null) {
                        
    return msg;
                    }

                    
    if (indexedTextName != null) {
                        msg 
    = getMessage(packageName, locale, indexedTextName, valueStack, args);

                        
    if (msg != null) {
                            
    return msg;
                        }
                    }
                }
            }

    假設(shè)你的action繼承樹是這樣
    com.bba96.core.webwork.actions.DefaultActionSupport
    com.xxxx.web.actions.XXXActionSupport
    com.xxxx.web.user.actions.UserAction
    com.xxxx.web.user.ViewUserAction
    且不說ww沒有判斷是否是com.opensymphony.xwork.ActionSupport或者ww的接口就停止,光是自己的繼承樹,就是4+3+3+3=13次,再加上往上的繼承樹以及對應(yīng)的接口,com.opensymphony.xwork.ActionSupport以及Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable, ContinuableObject的接口,查找次數(shù)超過30次甚至更多,這里的每一次都有一個同步miss的過程,開銷相當(dāng)大。

    如果你的key所在的resource bundle沒有對應(yīng)到合適的class或package時,例如說放在了default bundle中,ww會浪費(fèi)很多時間。這種情況下,我在沒有并發(fā)的時候測了一下,一次getText大概耗時40ms左右

    所以在實(shí)際應(yīng)用我們應(yīng)該避免這種情況出現(xiàn),要不讓resource bundle一一對應(yīng)class,要不就自己實(shí)現(xiàn)一個簡單的getText,其實(shí)要是ww的ActionSupport的textProvider允許改變就最好了。

    posted on 2006-01-21 13:26 李李 閱讀(1634) 評論(0)  編輯  收藏 所屬分類: 技術(shù)
    主站蜘蛛池模板: 久久精品一区二区免费看| 免费无码婬片aaa直播表情| 国产亚洲av片在线观看16女人 | 成人毛片免费观看视频大全| 亚洲第一精品电影网| 99爱在线观看免费完整版| 成人免费无码大片a毛片软件| 亚洲H在线播放在线观看H| 色网站在线免费观看| 国产免费AV片无码永久免费| 亚洲VA中文字幕无码毛片| 日韩免费视频一区二区| 久久久亚洲精品国产| 最近中文字幕免费完整| 亚洲综合区小说区激情区| 国产黄在线播放免费观看| 亚洲国产精品无码av| 亚洲人成网站色7799| 日本一道高清不卡免费| 亚洲毛片无码专区亚洲乱| 和日本免费不卡在线v| 亚洲五月综合缴情在线观看| 亚洲妇女熟BBW| 国产免费拔擦拔擦8x| 一级一看免费完整版毛片| 在线看片无码永久免费aⅴ| 日韩色日韩视频亚洲网站| 性xxxxx免费视频播放| 亚洲AV无码资源在线观看| 久久久久亚洲av毛片大| 无人在线观看免费高清| 一本色道久久88—综合亚洲精品| 免费a级毛片无码a∨性按摩| 国产午夜成人免费看片无遮挡| 免费国产在线观看不卡| 女人隐私秘视频黄www免费| 在线观看人成视频免费无遮挡| 亚洲网站在线观看| 日本在线看片免费| 一级有奶水毛片免费看| 亚洲AV午夜成人影院老师机影院|