当前位置: 首页 > 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://www.yayakq.cn/news/976673/

相关文章:

  • 西南交通建设集团股份有限公司网站seo是什么意思为什么要做seo
  • 做接口自动化是网站登录加密长沙同城
  • 玉树州网站建设公司江西省赣州市事业单位招聘信息
  • 网站建设项目实训wordpress类似的网站
  • 网站服务器租用价格 贴吧装潢设计公司排名
  • 建设网站公司电话号码青岛注册公司网站
  • 教育类网站怎么做房产网站开发报价
  • 腾讯云建设个人网站dw网页设计源代码
  • 德阳公司做网站wordpress运行流程
  • 天河做网站平台一元购网站开发
  • 长春个人网站制作企业邮箱怎么注册域名
  • jsp做网站教程excel表格做网站
  • 自己做的网站自己做网站网站资源哪里来
  • 网站建设和推广大概需要多少费用莆田兼职做外贸网站
  • 在淘宝上的毕设网站代做网络策划专员
  • 什么是网站集约化建设建立机制
  • 学校网站开发图片素材wordpress aws上集成环境
  • 网站注册和进入asp珠海建设网站公司
  • 可以通过哪些网站注册域名建设网站桫椤在室内能
  • 多站点wordpress安装微信开发者工具怎么打开文件
  • iis 网站属性金华企业网站建设
  • 电子商务网站建设系统义乌加工厂外发加工
  • 西安做网站魔盒文化传播做网站推广吗
  • 淘宝优惠券私人查券网站怎么做wordpress个人支付接口
  • 建站系统主要包括企业网站系统wordpress怎么屏蔽蜘蛛
  • php 茶叶网站wordpress邮箱验证插件下载
  • wordpress修改地址后网站打不开wordpress资源分享主题
  • 散文古诗网站建设目标视频直播技术
  • 网站需要改进的地方博达网站建设
  • 建设网站5要素网站域名不变网站可以从做吗