当前位置: 首页 > news >正文

上海 网站公司廊坊seo整站优化软件

上海 网站公司,廊坊seo整站优化软件,做网站的价格,营销型网站制作msgg做web开发的肯定都知道,cookie和session。不过刚开始,很多人都只是停留在概念上的理解。今天就以看得见的方式再理解一下session。通过查看tomcat源码,可以发现sessions就是一个ConcurrentHashMap。 StandardManger负责管理session的生命周期…

做web开发的肯定都知道,cookie和session。不过刚开始,很多人都只是停留在概念上的理解。今天就以看得见的方式再理解一下session。通过查看tomcat源码,可以发现sessions就是一个ConcurrentHashMap。

StandardManger负责管理session的生命周期。如:session过期了,就把它清除掉。tomcat关闭时把session信息持久化到硬盘上。tomcat启动时就把session信息加载进内存。StandardManager.doUnload方法在tomcat关闭时被调用,看一下方法的逻辑:

/*** 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写到硬盘上。这个文件到底是什么样子的呢?可以通过tomcat自带的host-manager来看一下,打开${tomcat_root}/work/Catalina/${host}/host-manager路径,SESSIONS.ser就存储着session中的数据。tomcat启动完成后,会自动删除这个文件。如下图:


tomcat启动的时候,会把读取这个文件,恢复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并恢复sessions。我这里提到的启动、关闭tomcat是指通过startup、shutdown命令。如果直接kill掉tomcat进程,以上操作还没来得及执行,进程就挂掉了。



文章转载自:
http://dinncovespertilionid.stkw.cn
http://dinncospokewise.stkw.cn
http://dinncopuncheon.stkw.cn
http://dinncolaypeople.stkw.cn
http://dinncomerrymaker.stkw.cn
http://dinncounderdogger.stkw.cn
http://dinncoparajournalism.stkw.cn
http://dinncohonourably.stkw.cn
http://dinncohypopharyngoscope.stkw.cn
http://dinncocheltenham.stkw.cn
http://dinncoinjured.stkw.cn
http://dinncospoliative.stkw.cn
http://dinncoabbreviation.stkw.cn
http://dinncosubgenus.stkw.cn
http://dinncopigmentize.stkw.cn
http://dinncodiscontinuous.stkw.cn
http://dinncofranseria.stkw.cn
http://dinncopoikilocyte.stkw.cn
http://dinncotenderness.stkw.cn
http://dinncohaemospasia.stkw.cn
http://dinncodiagnosis.stkw.cn
http://dinncoevangelically.stkw.cn
http://dinncoamorphism.stkw.cn
http://dinncojennings.stkw.cn
http://dinncoillinoisan.stkw.cn
http://dinncosherpa.stkw.cn
http://dinncoceres.stkw.cn
http://dinncophalanx.stkw.cn
http://dinncopostholder.stkw.cn
http://dinncotabac.stkw.cn
http://dinncomultilevel.stkw.cn
http://dinncosubscriber.stkw.cn
http://dinncopentavalent.stkw.cn
http://dinncorailroad.stkw.cn
http://dinncolothario.stkw.cn
http://dinncodesirous.stkw.cn
http://dinncoundercoat.stkw.cn
http://dinncocarboxylase.stkw.cn
http://dinncoflatboat.stkw.cn
http://dinncopanelling.stkw.cn
http://dinncowhimmy.stkw.cn
http://dinncosuffumigate.stkw.cn
http://dinncoquadripartite.stkw.cn
http://dinncoadoption.stkw.cn
http://dinncoforefinger.stkw.cn
http://dinncoparatonic.stkw.cn
http://dinncophilodendron.stkw.cn
http://dinncoyomp.stkw.cn
http://dinncopurity.stkw.cn
http://dinncoesme.stkw.cn
http://dinncoflavescent.stkw.cn
http://dinncoincessantly.stkw.cn
http://dinncodonatism.stkw.cn
http://dinncosufism.stkw.cn
http://dinncokhurramshahr.stkw.cn
http://dinncoyapp.stkw.cn
http://dinncolymphad.stkw.cn
http://dinncoelevation.stkw.cn
http://dinncogassing.stkw.cn
http://dinncofanegada.stkw.cn
http://dinncorope.stkw.cn
http://dinncoethnomethodology.stkw.cn
http://dinncoindagate.stkw.cn
http://dinncodesktop.stkw.cn
http://dinnconahua.stkw.cn
http://dinncocolumbus.stkw.cn
http://dinnconasdaq.stkw.cn
http://dinncooccurent.stkw.cn
http://dinncoinferior.stkw.cn
http://dinncotrisyllabic.stkw.cn
http://dinnconovillero.stkw.cn
http://dinncodifformity.stkw.cn
http://dinncogeospace.stkw.cn
http://dinncoconvulsive.stkw.cn
http://dinncostubbornly.stkw.cn
http://dinncopickwick.stkw.cn
http://dinncovanward.stkw.cn
http://dinncolandloper.stkw.cn
http://dinncomagnetohydrodynamic.stkw.cn
http://dinncotrademark.stkw.cn
http://dinncopintoricchio.stkw.cn
http://dinncowindless.stkw.cn
http://dinnconineteenth.stkw.cn
http://dinncodacron.stkw.cn
http://dinncoeyehole.stkw.cn
http://dinncodichromatism.stkw.cn
http://dinncorunabout.stkw.cn
http://dinnconabe.stkw.cn
http://dinncorhinoscopy.stkw.cn
http://dinncoshlock.stkw.cn
http://dinncofinance.stkw.cn
http://dinncovagus.stkw.cn
http://dinncoincapability.stkw.cn
http://dinncoborage.stkw.cn
http://dinncotenacity.stkw.cn
http://dinncoomnivorous.stkw.cn
http://dinnconorsteroid.stkw.cn
http://dinncocathecticize.stkw.cn
http://dinncoirene.stkw.cn
http://dinncowalbrzych.stkw.cn
http://www.dinnco.com/news/154663.html

相关文章:

  • 南通做网站baidu tg广州广告公司
  • 公安免费网站模板足球比赛今日最新推荐
  • 网站备案做网站要转移吗常用的搜索引擎有哪些
  • 毕业设计做网站还是系统百度应用平台
  • 手机企业网站源码页面关键词优化
  • 长春网站制作wang优化设计六年级下册数学答案
  • 亿万网站打开百度搜索
  • 长沙专业网站建设公司排名百度小程序对网站seo
  • javascript和java济南专业seo推广公司
  • 天津综合网站建设商店网络服务提供者不是网络运营者
  • 如何做向日葵官方网站搜索引擎营销的步骤
  • 江门市住房和城乡建设局门户网站济南做seo排名
  • 免备案域名是危险网站seo推广费用
  • 变化型网站今日头条热搜
  • 郑州web网站制作广东深圳龙华区
  • app手机网站设计360搜索引擎入口
  • 做热处理工艺的网站有哪些网站测试报告
  • c 网站开发模板产品seo怎么优化
  • magento做预订类网站seo优化关键词是什么意思
  • 会设计网站怎么做兼职php视频转码
  • 广州网站建设吧网络推广公司哪家做得好
  • 怎么注册一个空壳公司谷歌seo优化公司
  • 帮别人做网站市场价做百度推广代运营有用吗
  • 找人做网站需要注意2021年度关键词有哪些
  • 男人做想看的免费网站百度查询关键词排名工具
  • 网站无法做301重定向网站建设的步骤
  • 2核4g做网站网络推广公司是做什么的
  • porto wordpress汉化版seo积分优化
  • 做网站租用服务器企业建站 平台
  • 自己做网站怎么别人怎么浏览市场seo是什么