tomcat原始碼閱讀的趣事1

2021-07-28 07:58:15 字數 1555 閱讀 9294

最近在感情上受挫了,然後實在是很無聊了,之後就開始閱讀起來tomcat的源**了,看到了下面比較搞笑的一幕,不知道大家什麼體會:

/**

* system property replacement in the given string.

* 我很納悶啊,這個要是

spring

的風格,指定是給你乙個

stringutils

的類給出來這個字串的操作,

* 不知道

tomcat

是什麼鬼,這麼設計這個**啊

* 說句實話啊,不是說針對

tomcat

什麼的,我真呢是覺得

tomcat

的作者是從

c++的模式下切換過來的。這**就是:故佈疑陣

* 感覺

tomcat

的作者真是逗啊,本來兩行就可以解決的問題,非要自己重新寫一遍解析的過程,再說了,這個是在啟動的時候,就算是兩次字串的替換

* 對效能也沒有什麼影響啊**

@param

str

the original string

* @return

the modified string

*/protected string replace(string str) "

, getcatalinabase());

tempinfostr = tempinfostr.replaceall("\\$

\\", getcatalinahome());

showinfo.printdetailinfo(this,

"我自己替換的模式

", tempinfostr);

int pos_start = str.indexof("$'

, pos_start + 2);

if (pos_end < 0)

string propname = str.substring(pos_start + 2

, pos_end);

string replacement;

if (propname.length() == 0) else if (globals.catalina_home_prop.equals(propname)) else if (globals.catalina_base_prop.equals(propname)) else

if (replacement != null) else

pos_start = str.indexof("$

, str.length());

result = builder.tostring();

} showinfo.printdetailinfo(this,

"tomcat

自己替換的結果:

" + result);

if (result.equals(tempinfostr))

return result;

}

我的體會就是:tomcat的作者是不是從c++轉過來的,總是喜歡親自操刀動手解剖string為char進行操作

Tomcat原始碼閱讀系列

再過十來天,就要不再是大三,而步入大四的殿堂了,求職面試的事會接踵而至,鑑於春招時的教訓,自己的學習比較缺乏系統性地整理,向他人交流自己所掌握的技術能力仍有待提高,為此將自己閱讀tomcat原始碼的過程記錄一下,並分享到部落格中,讓有同樣興趣的同學一起交流討論。注 如沒有特別說明的地方,tomcat...

tomcat原始碼閱讀16

org.apache.catalina.session包 該包包括標準manager和session的實現,用於表示活動的session和獨立的session,他們都與相應的上下文相關聯。constants 該包的常量 filestore store介面的實現,將session儲存到配置目錄的檔案中...

tomcat原始碼閱讀5

org.apache.catalina.cluster.authenticator包 clustersinglesignon 每個valve支援使用者單點登入在集群節點上,使用者在web應用程式上經過驗證的安全標誌可以在同乙個安全域的其它集群節點上使用 clustersinglesignonlist...