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

html静态页面怎么放在网站上做流量网站挂广告还能挣钱吗

html静态页面怎么放在网站上,做流量网站挂广告还能挣钱吗,天津网站建设品牌推广,东莞网站推广策划摘要#xff1a;PersistentManager与StandardManager的异同。 之前两篇关于session的文章主要讨论了session相关的创建、查询、过期处理。而我们查看源码的时候都是默认实现是StandardManager类#xff0c;实际上实现也可以是PersistentManager类#xff0c;下面我们就查看下…摘要PersistentManager与StandardManager的异同。 之前两篇关于session的文章主要讨论了session相关的创建、查询、过期处理。而我们查看源码的时候都是默认实现是StandardManager类实际上实现也可以是PersistentManager类下面我们就查看下该类的相关方法。 我们都知道PersistentManager代表的是持久化session的管理器。在PersistentManager类定义中有个变量org.apache.catalina.Store该变量表示session管理器持久化session的方式具体类图如下 Store 持久化存储方式的抽象类定义了一些基本方法例如save(),load(),keys(),clear()等。save()用来将session持久化到持久性介质中。load()方法从持久化介质中读取到内存中keys()则返回所有的sessionId数组。clear()则清除所有的session。 StoreBase 抽象类对Store作了基本实现。 FileStore 该类会将session对象存储到某个文件中文件名会使用session对象的标识符再加上一个后缀.session构成。文件位于临时目录下也可以调用FileStore类的setDirectroy()方法修改目录。 JDBCStore 该类将session对象通过jdbc存入数据库因此使用该类需要使用jdbc链接。 鉴于save(),load()源码都很简单这里就不一一查看了。 我们继续讨论PersistentManager类相关方法。 在Request的doGetSession()方法中我们之前默认manager实现类是StandardManager,如果tomcat中配置的是PersistentManager,那么manager.findSession(requestedSessionId)会略有不同我们查看下源码(在PersistentManagerBase类中) Override public Session findSession(String id) throws IOException {//调用父类的findSession() 也就是ManagerBase类中的findSession,从现有内存中查找是否有指定的sessionSession session super.findSession(id);// OK, at this point, were not sure if another thread is trying to// remove the session or not so the only way around this is to lock it// (or attempt to) and then try to get it by this session id again. If// the other code ran swapOut, then we should get a null back during// this run, and if not, we lock it out so we can access the session// safely.//翻译下 英文注释// 代码运行到这里因为我们不确定是否有别的线程要移除这个session所以最保险的办法就是加锁再次尝试获取该session// 如果有其他代码正在执行 swapOut(将内存session持久化到介质中那么我们应该返回null如果没有的话那么我们就可以安全的访问这个sessionif(session ! null) {synchronized(session){session super.findSession(session.getIdInternal());if(session ! null){// To keep any external calling code from messing up the// concurrency.session.access();session.endAccess();}}}// 再次判断if (session ! null)return session;// See if the Session is in the Store//从持久化介质中查找 session是否存在session swapIn(id);return session; } 查看 swapIn()方法 /*** Look for a session in the Store and, if found, restore* it in the Managers list of active sessions if appropriate.* The session will be removed from the Store after swapping* in, but will not be added to the active session list if it* is invalid or past its expiration.** return restored session, or {code null}, if none is found*//*** 在Store(存储介质)中查找session如果发现将把session恢复到该Manager的活跃session集合中。* 这个session将会从Store中移除但是如果session过期或者无效将不会添加到活跃集合。*/protected Session swapIn(String id) throws IOException {if (store null)return null;Object swapInLock null;/** The purpose of this sync and these locks is to make sure that a* session is only loaded once. It doesnt matter if the lock is removed* and then another thread enters this method and tries to load the same* session. That thread will re-create a swapIn lock for that session,* quickly find that the session is already in sessions, use it and* carry on.*/synchronized (this) {swapInLock sessionSwapInLocks.get(id);if (swapInLock null) {swapInLock new Object();sessionSwapInLocks.put(id, swapInLock);}}Session session null;synchronized (swapInLock) {// First check to see if another thread has loaded the session into// the managersession sessions.get(id);if (session null) {try {if (SecurityUtil.isPackageProtectionEnabled()){try {session AccessController.doPrivileged(new PrivilegedStoreLoad(id));} catch (PrivilegedActionException ex) {Exception e ex.getException();log.error(sm.getString(persistentManager.swapInException, id),e);if (e instanceof IOException){throw (IOException)e;} else if (e instanceof ClassNotFoundException) {throw (ClassNotFoundException)e;}}} else {//加载session//1111111session store.load(id);}} catch (ClassNotFoundException e) {String msg sm.getString(persistentManager.deserializeError, id);log.error(msg, e);throw new IllegalStateException(msg, e);}if (session ! null !session.isValid()) {log.error(sm.getString(persistentManager.swapInInvalid, id));session.expire();removeSession(id);session null;}if (session ! null) {if(log.isDebugEnabled())log.debug(sm.getString(persistentManager.swapIn, id));session.setManager(this);// make sure the listeners know about it.((StandardSession)session).tellNew();add(session);((StandardSession)session).activate();// endAccess() to ensure timeouts happen correctly.// access() to keep access count correct or it will end up// negativesession.access();session.endAccess();}}}// Make sure the lock is removedsynchronized (this) {sessionSwapInLocks.remove(id);}return session; } 可以看到主要的核心代码就是标注1的地方Store.load(id),而这个源码配合Store.save(session)不管是FileStore还是JDBCStore都是很简单的所以就不查看了。 除了getSession()方法有不同的地方周期性任务的方法也略有不同。 在ManagerBase的backgroundProcess()方法中 Override public void backgroundProcess() {count (count 1) % processExpiresFrequency;if (count 0)processExpires(); } 因为processExpires()方法PersitentManagerBase中有复写的方法所以会调用子类的方法。 Override public void processExpires() {//111111111long timeNow System.currentTimeMillis();Session sessions[] findSessions();int expireHere 0 ;if(log.isDebugEnabled())log.debug(Start expire sessions getName() at timeNow sessioncount sessions.length);for (int i 0; i sessions.length; i) {if (!sessions[i].isValid()) {expiredSessions.incrementAndGet();expireHere;}}//222222processPersistenceChecks();if ((getStore() ! null) (getStore() instanceof StoreBase)) {((StoreBase) getStore()).processExpires();}long timeEnd System.currentTimeMillis();if(log.isDebugEnabled())log.debug(End expire sessions getName() processingTime (timeEnd - timeNow) expired sessions: expireHere);processingTime (timeEnd - timeNow);} 在标注1到标注2之间的代码和之前查看的并无区别基本就是将内存中的session一个个过期检查下。接着调用了processPersistenceChecks()方法。 public void processPersistenceChecks() {//空闲时间超出一定的存储到存储器中processMaxIdleSwaps();//活跃session超出一定比例的存储到存储器中processMaxActiveSwaps();//空闲时间超出一定时间的进行备份processMaxIdleBackups(); } 因为三个方法都相差不大就着了其中一个来查看下 /*** Swap idle sessions out to Store if they are idle too long.*/ protected void processMaxIdleSwaps() {if (!getState().isAvailable() || maxIdleSwap 0)return;//获取所有的sessionSession sessions[] findSessions();long timeNow System.currentTimeMillis();// Swap out all sessions idle longer than maxIdleSwap//一个变量在server.xml里可以配置session的最大空闲时间超出session会被保存到存储器中如果是负数那么永远不保存if (maxIdleSwap 0) {for (int i 0; i sessions.length; i) {StandardSession session (StandardSession) sessions[i];synchronized (session) {if (!session.isValid())continue;int timeIdle;if (StandardSession.LAST_ACCESS_AT_START) {timeIdle (int) ((timeNow - session.getLastAccessedTimeInternal()) / 1000L);} else {timeIdle (int) ((timeNow - session.getThisAccessedTimeInternal()) / 1000L);}if (timeIdle maxIdleSwap timeIdle minIdleSwap) {if (session.accessCount ! null session.accessCount.get() 0) {// Session is currently being accessed - skip itcontinue;}if (log.isDebugEnabled())log.debug(sm.getString(persistentManager.swapMaxIdle,session.getIdInternal(),Integer.valueOf(timeIdle)));try {//11111swapOut(session);} catch (IOException e) {// This is logged in writeSession()}}}}}} 查看标注1 的 swapOut(session) protected void swapOut(Session session) throws IOException {if (store null || !session.isValid()) {return;}((StandardSession)session).passivate();//222//写入到存储器中writeSession(session);//从活跃session名单中移除也就是内存中移除super.remove(session, true);//回收session对象session.recycle();} 查看标注2的writeSession() protected void writeSession(Session session) throws IOException {if (store null || !session.isValid()) {return;}try {if (SecurityUtil.isPackageProtectionEnabled()){try{AccessController.doPrivileged(new PrivilegedStoreSave(session));}catch(PrivilegedActionException ex){Exception exception ex.getException();if (exception instanceof IOException) {throw (IOException) exception;}log.error(Exception in the Store during writeSession: exception, exception);}} else {//3333333store.save(session);} } catch (IOException e) {log.error(sm.getString(persistentManager.serializeError, session.getIdInternal(), e));throw e;}} 可以看出最后还是调用的store.save(session)方法就不再查看了其他的processMaxActiveSwaps(),processMaxIdleBackups()方法都很类似就留给读者自行查看了。 总的来说PersistentManager与StandardManager区别在于PersistentManager在StandardManager的基础上额外增加了存储的功能不管查找删除还是保存都需要在内存和存储器中同时进行。 总结本文讨论了session管理器该组件用来管理session管理中的session对象解释了不同管理器的区别以及session管理器如何把内存中session持久化到存储器中 最后附上相关配置 在web.xml中配置 session 的过期时间默认30min session-configsession-timeout30/session-timeout /session-config 在server.xml中配置 session管理器默认StandardManager可以不配置如果需要配置全局的session manager,可以在conf/context.xml中配置 StandardManager 当Tomcat服务器关闭或重启或者Web应用被重新加载时会对在内存中的HttpSession对象进行持久化 并把它们保存到文件系统中默认的文件为$CATALINA_HOME/work/Catalina/hostname/applicationname/SESSIONS.ser 在Context/Context标签内配置Manager/Manager标签 Manager classNameorg.apache.catalina.session.StandardManager maxInactiveInterval-1 / 备注如果服务器异常关闭则所有会话都会丢失StandardManager没有机会进行存盘处理 PersistentManager Manager classNameorg.apache.catalina.session.PersistentManager saveOnRestarttruemaxActiveSessions-1minIdleSwap60maxIdleSwap60maxIdleBackup60!--Store classNameorg.apache.catalina.session.FileStore directory../session /--Store classNameorg.apache.catalina.session.JDBCStoredriverNamecom.mysql.jdbc.Driver connectionURLjdbc:mysql://url?useruseramp;passwordpsdsessionTabletomcat_session sessionIdColsession_id sessionDataColsession_data sessionValidColsession_valid sessionMaxInactiveColmax_inactive sessionLastAccessedCollast_accesssessionAppColapp_name / /Manager saveOnRestart:是否在重启的时候加载保存sessionmaxActiveSessions最大允许session数量-1 不限制minIdleSwap最小空闲时间超出将会被转存到存储器中maxIdleSwap最大空闲时间超出将会被转存到存储器中Store相关 directory采用FileStore的时候指存储session的目录sessionTable存储session的表名sessionIdColsessionid列名sessionDataColsessionData列名sessionValidColsession是否有效列名sessionMaxInactiveColsession最大闲置时间列名sessionLastAccessedColsession上次访问时间列名sessionAppColsession归属的应用名称列名(完) 转载于:https://www.cnblogs.com/coldridgeValley/p/6096143.html
http://www.zqtcl.cn/news/758413/

相关文章:

  • vip影视网站怎么做的辽宁建设厅网站什么时候换的
  • 搭建个网站网站维护合同模板
  • 优盖网logo在线设计南通做网站优化的公司
  • 做百度糯米网站的团队新媒体营销推广公司
  • 个人做网站的时代已经过去大连男科医院排名表
  • 天津餐饮网站建设贵港做网站化司
  • 昆山哪家做网站好猪八戒网站建设
  • 网站的静态资源服务器怎么做河北网站备案
  • php儿童摄影网站源码东莞做网站的公司哪家最好
  • 金融投资网站建设wordpress九宫格主题
  • 玉田县网站建设手机网站建设西安
  • 高质量外链网站请大学生做网站
  • 2021能看的网站不要app贴吧网站以前在百度能搜索不到了
  • 个人做网站时不要做什么样的网站百度网站排名全掉
  • 鹤岗做网站制作企业网站需要注意的事项
  • 网站建设服务器是什么意思短网址转换器
  • 红叶网站开发工作室整站优化费用
  • 温州网站建站模板建设小企业网站步骤
  • 免费企业网站我为什么电商要学网站建设
  • 建设网站员工招聘策划方案win2012 iis配置网站
  • 织梦cms 5.6网站地图图标怎么在wordpress
  • instagram wordpress北京seo学校
  • 网站优化的基本思想企业网站建设和运营
  • 网站开发电销常遇到问题怎么建立一个群
  • worldpress 建站少儿编程加盟费一般多少钱
  • 哪个公司做网站建设好九一人才网赣州招聘官网
  • 城阳区规划建设局网站哈尔滨网站建设好
  • 中小型网站建设价位无锡有哪些互联网公司
  • 网站内容收费jquery 网站框架
  • 自己建网站买玩具外贸网站如何做推广