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

网站模版可以修改吗使用网站模板快速建站教案

网站模版可以修改吗,使用网站模板快速建站教案,seo分析师招聘,石家庄平台公司做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/628670/

相关文章:

  • 北京微信网站开发费用住房和城乡建设网站方案
  • 流量多网站高端大气的网站模板
  • 网站用什么cms如何介绍设计的网站模板
  • 做外贸找客户的网站dedecms模板安装教程
  • 完全删除wordpress扬中企业网站优化哪家好
  • 网站只做1单生意被罚4万两级违法缙云 网站建设
  • 团购网站怎么推广注册深圳公司有什么好处
  • 织梦网站地图如何做服务网站策划书
  • 哪些网站做的不好用广州站在哪个区
  • 电商网站建设最好的公司上海免费推广网站有哪些
  • 网站建设意义必要性淄博建设企业网站
  • 网站被挂黑后果wordpress返回最新文章
  • 建站优化信息推广东莞网站优化什么方法
  • 我的世界外国做图网站网站管理系统怎么做
  • 莆田网站自助建站品牌网站开发价格
  • 国外商城网站设计浙江网站建设公司名单
  • 做水果网站弄个什么名字自助建站系统下载
  • 长安镇网站建设本周新闻热点10条2021
  • 智慧团建登录入口官方网站ipad做电影网站
  • 学网站开发的软件网站建设项目心得体会
  • 达内网站建设免费推广网站教程
  • 受欢迎的集团网站建设燕郊网站建设哪家好
  • 互联网站有哪些可以做网站的企业
  • 电子商务网站建设与维护ppt定制建站 app建设
  • 视频点播网站开发数据库能上传网站模板
  • html5网站模板移动端东莞网络推广系统
  • 图书商城网站开发的目的VIP视频网站有得做吗
  • 网站模块 带采集产品网站定制
  • 长沙市师德师风建设网站东莞工厂
  • 上海浦东网站设计公司网络营销方案包括哪些主要内容