国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

響應(yīng)網(wǎng)站 整屏seo學(xué)院

響應(yīng)網(wǎng)站 整屏,seo學(xué)院,建設(shè)銀行貴陽市網(wǎng)站電話,杭州pc網(wǎng)站制作公司做web開發(fā)的肯定都知道,cookie和session。不過剛開始,很多人都只是停留在概念上的理解。今天就以看得見的方式再理解一下session。通過查看tomcat源碼,可以發(fā)現(xiàn)sessions就是一個(gè)ConcurrentHashMap。 StandardManger負(fù)責(zé)管理session的生命周期…

做web開發(fā)的肯定都知道,cookie和session。不過剛開始,很多人都只是停留在概念上的理解。今天就以看得見的方式再理解一下session。通過查看tomcat源碼,可以發(fā)現(xiàn)sessions就是一個(gè)ConcurrentHashMap。

StandardManger負(fù)責(zé)管理session的生命周期。如:session過期了,就把它清除掉。tomcat關(guān)閉時(shí)把session信息持久化到硬盤上。tomcat啟動(dòng)時(shí)就把session信息加載進(jìn)內(nèi)存。StandardManager.doUnload方法在tomcat關(guān)閉時(shí)被調(diào)用,看一下方法的邏輯:

/*** Save any currently active sessions in the appropriate persistence* mechanism, if any.  If persistence is not supported, this method* returns without doing anything.** @exception IOException if an input/output error occurs*/protected void doUnload() throws IOException {if (log.isDebugEnabled())log.debug("Unloading persisted sessions");// Open an output stream to the specified pathname, if anyFile file = file();if (file == null)return;if (log.isDebugEnabled())log.debug(sm.getString("standardManager.unloading", pathname));FileOutputStream fos = null;ObjectOutputStream oos = null;try {fos = new FileOutputStream(file.getAbsolutePath());oos = new ObjectOutputStream(new BufferedOutputStream(fos));} catch (IOException e) {log.error(sm.getString("standardManager.unloading.ioe", e), e);if (oos != null) {try {oos.close();} catch (IOException f) {;}oos = null;}throw e;}// Write the number of active sessions, followed by the detailsArrayList list = new ArrayList();synchronized (sessions) {if (log.isDebugEnabled())log.debug("Unloading " + sessions.size() + " sessions");try {oos.writeObject(new Integer(sessions.size()));Iterator elements = sessions.values().iterator();while (elements.hasNext()) {StandardSession session =(StandardSession) elements.next();list.add(session);((StandardSession) session).passivate();session.writeObjectData(oos);}} catch (IOException e) {log.error(sm.getString("standardManager.unloading.ioe", e), e);if (oos != null) {try {oos.close();} catch (IOException f) {;}oos = null;}throw e;}}// Flush and close the output streamtry {oos.flush();oos.close();oos = null;} catch (IOException e) {if (oos != null) {try {oos.close();} catch (IOException f) {;}oos = null;}throw e;}// Expire all the sessions we just wroteif (log.isDebugEnabled())log.debug("Expiring " + list.size() + " persisted sessions");Iterator expires = list.iterator();while (expires.hasNext()) {StandardSession session = (StandardSession) expires.next();try {session.expire(false);} catch (Throwable t) {;} finally {session.recycle();}}if (log.isDebugEnabled())log.debug("Unloading complete");}
邏輯很簡單,就是通過文件流將sessions寫到硬盤上。這個(gè)文件到底是什么樣子的呢?可以通過tomcat自帶的host-manager來看一下,打開${tomcat_root}/work/Catalina/${host}/host-manager路徑,SESSIONS.ser就存儲著session中的數(shù)據(jù)。tomcat啟動(dòng)完成后,會(huì)自動(dòng)刪除這個(gè)文件。如下圖:


tomcat啟動(dòng)的時(shí)候,會(huì)把讀取這個(gè)文件,恢復(fù)sessions。

/*** Load any currently active sessions that were previously unloaded* to the appropriate persistence mechanism, if any.  If persistence is not* supported, this method returns without doing anything.** @exception ClassNotFoundException if a serialized class cannot be*  found during the reload* @exception IOException if an input/output error occurs*/protected void doLoad() throws ClassNotFoundException, IOException {if (log.isDebugEnabled())log.debug("Start: Loading persisted sessions");// Initialize our internal data structuressessions.clear();// Open an input stream to the specified pathname, if anyFile file = file();if (file == null)return;if (log.isDebugEnabled())log.debug(sm.getString("standardManager.loading", pathname));FileInputStream fis = null;ObjectInputStream ois = null;Loader loader = null;ClassLoader classLoader = null;try {fis = new FileInputStream(file.getAbsolutePath());BufferedInputStream bis = new BufferedInputStream(fis);if (container != null)loader = container.getLoader();if (loader != null)classLoader = loader.getClassLoader();if (classLoader != null) {if (log.isDebugEnabled())log.debug("Creating custom object input stream for class loader ");ois = new CustomObjectInputStream(bis, classLoader);} else {if (log.isDebugEnabled())log.debug("Creating standard object input stream");ois = new ObjectInputStream(bis);}} catch (FileNotFoundException e) {if (log.isDebugEnabled())log.debug("No persisted data file found");return;} catch (IOException e) {log.error(sm.getString("standardManager.loading.ioe", e), e);if (ois != null) {try {ois.close();} catch (IOException f) {;}ois = null;}throw e;}// Load the previously unloaded active sessionssynchronized (sessions) {try {Integer count = (Integer) ois.readObject();int n = count.intValue();if (log.isDebugEnabled())log.debug("Loading " + n + " persisted sessions");for (int i = 0; i < n; i++) {StandardSession session = getNewSession();session.readObjectData(ois);session.setManager(this);sessions.put(session.getIdInternal(), session);session.activate();session.endAccess();}} catch (ClassNotFoundException e) {log.error(sm.getString("standardManager.loading.cnfe", e), e);if (ois != null) {try {ois.close();} catch (IOException f) {;}ois = null;}throw e;} catch (IOException e) {log.error(sm.getString("standardManager.loading.ioe", e), e);if (ois != null) {try {ois.close();} catch (IOException f) {;}ois = null;}throw e;} finally {// Close the input streamtry {if (ois != null)ois.close();} catch (IOException f) {// ignored}// Delete the persistent storage fileif (file != null && file.exists() )file.delete();}}if (log.isDebugEnabled())log.debug("Finish: Loading persisted sessions");}
以上整體的邏輯就是,通過文件流讀取SESSIONS.ser并恢復(fù)sessions。我這里提到的啟動(dòng)、關(guān)閉tomcat是指通過startup、shutdown命令。如果直接kill掉tomcat進(jìn)程,以上操作還沒來得及執(zhí)行,進(jìn)程就掛掉了。


http://m.aloenet.com.cn/news/32970.html

相關(guān)文章:

  • 開一個(gè)網(wǎng)站需要什么seo排名賺下載
  • 網(wǎng)站備案 深圳廣告投放的方式有哪些
  • 網(wǎng)站建設(shè) 個(gè)人杭州明開seo
  • ovz的vps怎么做網(wǎng)站建設(shè)企業(yè)網(wǎng)站多少錢
  • wordpress如何添加菜單和數(shù)據(jù)表搜索引擎優(yōu)化的目的是對用戶友好
  • 建設(shè)公司企業(yè)簡介北京推廣優(yōu)化公司
  • 裝修網(wǎng)站合作百度官方網(wǎng)站入口
  • 司機(jī)找事做那個(gè)網(wǎng)站靠譜北京網(wǎng)站制作推廣
  • 潛江資訊網(wǎng)免費(fèi)發(fā)布信息手機(jī)端seo
  • 最簡單做網(wǎng)站國際熱點(diǎn)事件
  • 做澳洲ets上什么網(wǎng)站網(wǎng)站seo如何優(yōu)化
  • 寧波市住房和城鄉(xiāng)建設(shè)委員網(wǎng)站網(wǎng)絡(luò)銷售培訓(xùn)
  • 福田企業(yè)網(wǎng)站優(yōu)化哪個(gè)好推廣軟文范例100字
  • 玉溪做網(wǎng)站公司重慶網(wǎng)站搜索引擎seo
  • WordPress 站點(diǎn)圖標(biāo)鏈接站長素材網(wǎng)站
  • 營銷型企業(yè)網(wǎng)站分析與診斷關(guān)鍵詞挖掘站長工具
  • 微信公眾號免費(fèi)模板網(wǎng)站化妝品推廣軟文
  • 有什么知名網(wǎng)站是用織夢做的微信營銷模式
  • 私人可注冊網(wǎng)站嗎吉林黃頁電話查詢
  • 網(wǎng)站直播是未開票收入怎么做淘客推廣怎么做
  • 萬網(wǎng)網(wǎng)站域名百度網(wǎng)盤下載的文件在哪
  • 蘭州網(wǎng)站建設(shè)多少錢河南做網(wǎng)站優(yōu)化
  • 海南百度網(wǎng)站建設(shè)成都網(wǎng)站seo公司
  • 合川網(wǎng)站建設(shè)網(wǎng)絡(luò)營銷前景和現(xiàn)狀分析
  • 石家莊 網(wǎng)站開發(fā)菏澤seo
  • 畢業(yè)設(shè)計(jì)網(wǎng)站開發(fā)題目拓客最有效方案
  • vs做網(wǎng)站怎樣加數(shù)據(jù)庫正規(guī)培訓(xùn)機(jī)構(gòu)有哪些
  • 做電池的外貿(mào)網(wǎng)站全國唯一一個(gè)沒有疫情的城市
  • 深圳知名網(wǎng)站建設(shè)供應(yīng)seo排名賺掛機(jī)賺錢軟件下載
  • 上海社會(huì)建設(shè)網(wǎng)站北京百度搜索排名優(yōu)化