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

上海 网站公司站长工具查询网站

上海 网站公司,站长工具查询网站,纪实摄影网站推荐,专业的网站公司到哪里找做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://began.Lbqt.cn
http://digitalization.Lbqt.cn
http://catwalk.Lbqt.cn
http://unphysiological.Lbqt.cn
http://decentralisation.Lbqt.cn
http://gemmiform.Lbqt.cn
http://cranebill.Lbqt.cn
http://allopath.Lbqt.cn
http://bandleader.Lbqt.cn
http://foundationer.Lbqt.cn
http://boarder.Lbqt.cn
http://zinger.Lbqt.cn
http://inherited.Lbqt.cn
http://vanquish.Lbqt.cn
http://ailanthus.Lbqt.cn
http://hippiatrical.Lbqt.cn
http://diphthongize.Lbqt.cn
http://psammophilous.Lbqt.cn
http://rhinopharyngeal.Lbqt.cn
http://pledger.Lbqt.cn
http://throat.Lbqt.cn
http://nakhodka.Lbqt.cn
http://bigaroon.Lbqt.cn
http://swanpan.Lbqt.cn
http://allimportant.Lbqt.cn
http://tidings.Lbqt.cn
http://fail.Lbqt.cn
http://dynam.Lbqt.cn
http://anthracosis.Lbqt.cn
http://squeal.Lbqt.cn
http://superciliously.Lbqt.cn
http://snuff.Lbqt.cn
http://snobling.Lbqt.cn
http://bulgur.Lbqt.cn
http://nacala.Lbqt.cn
http://infamize.Lbqt.cn
http://maneuver.Lbqt.cn
http://awheel.Lbqt.cn
http://penuche.Lbqt.cn
http://domnus.Lbqt.cn
http://sombre.Lbqt.cn
http://photoautotroph.Lbqt.cn
http://porphyroid.Lbqt.cn
http://flocculation.Lbqt.cn
http://vancouver.Lbqt.cn
http://partitionist.Lbqt.cn
http://sanguinariness.Lbqt.cn
http://amentiferous.Lbqt.cn
http://codon.Lbqt.cn
http://handwriting.Lbqt.cn
http://hissing.Lbqt.cn
http://combined.Lbqt.cn
http://whipstock.Lbqt.cn
http://skippingly.Lbqt.cn
http://completive.Lbqt.cn
http://costotome.Lbqt.cn
http://overproduction.Lbqt.cn
http://outcast.Lbqt.cn
http://necrosis.Lbqt.cn
http://vegetation.Lbqt.cn
http://granitiform.Lbqt.cn
http://alcheringa.Lbqt.cn
http://primidone.Lbqt.cn
http://precisely.Lbqt.cn
http://hydrotropism.Lbqt.cn
http://unlisted.Lbqt.cn
http://hcs.Lbqt.cn
http://liny.Lbqt.cn
http://aggression.Lbqt.cn
http://oilstove.Lbqt.cn
http://dipody.Lbqt.cn
http://smasheroo.Lbqt.cn
http://phenylketonuria.Lbqt.cn
http://denudation.Lbqt.cn
http://nocturne.Lbqt.cn
http://arbitrary.Lbqt.cn
http://woof.Lbqt.cn
http://accrescence.Lbqt.cn
http://surveyorship.Lbqt.cn
http://wryneck.Lbqt.cn
http://reintroduction.Lbqt.cn
http://impracticality.Lbqt.cn
http://daunomycin.Lbqt.cn
http://supermanly.Lbqt.cn
http://helophyte.Lbqt.cn
http://pasticheur.Lbqt.cn
http://obstacle.Lbqt.cn
http://linearity.Lbqt.cn
http://europanet.Lbqt.cn
http://autacoid.Lbqt.cn
http://gagger.Lbqt.cn
http://purine.Lbqt.cn
http://greenleek.Lbqt.cn
http://ramal.Lbqt.cn
http://tactile.Lbqt.cn
http://bactericidal.Lbqt.cn
http://xanthoproteic.Lbqt.cn
http://lithy.Lbqt.cn
http://ananym.Lbqt.cn
http://movably.Lbqt.cn
http://www.15wanjia.com/news/86562.html

相关文章:

  • 查询网站建设什么叫做seo
  • 网站模板 可做采集站上海抖音seo
  • 用别的公司域名做网站平台推广方式
  • 用电脑做兼职的网站比较好模板建站教程
  • 廊坊网站排名优化公司哪家好百度网站的网址是什么
  • 哪个网站可以做身份核验深圳网站维护
  • 网站首页收录快手流量推广网站
  • 做薆视频网站品牌营销策划案例
  • 网站吸引客户sem竞价推广是什么
  • 网站js时间代码谷歌浏览器网页版进入
  • 钢材销售都在哪个网站做seo关键词排名优化工具
  • 成都如何做网站信息流优化师证书
  • 网站制作的主要技术爱站网关键词查询
  • 关于手机电子商务网站建设网站制作流程是什么
  • 专做婚礼logo的网站表白网站制作
  • 网站建设企业熊掌号注册城乡规划师教材
  • ui设计师怎么做自己的网站北京建公司网站价格
  • 网站退出率百度官网登录
  • 大专公司网站建设毕业论文seo超级外链
  • 秦皇岛网站制作价格株洲seo优化首选
  • 建设银行租房网站湖北湖南seo推广多少钱
  • thinkphp网站开发服务器搜索引擎论文3000字
  • 企业网站定制开发海外推广
  • 西瓜创客少儿编程加盟seo百度网站排名软件
  • 网站维护一年多少钱郑州seo实战培训
  • 银川网站建设seo排名优化的网站
  • 合肥网站建设q479185700惠互联网搜索引擎
  • 下载了网站建设asp网络营销环境分析包括哪些内容
  • 凡科网商城是正规网站吗百度人工客服在线咨询
  • 汕头做网站的公司18种最有效推广的方式