有这个想法是在很早以前了,那时的我没有接触什么缓存技术,只知道hibernate有个二级缓存。没有用过memcache,也没有使用过redis。

只懂得将数据放到数组里或者集合里,一直不去销毁它(只有随着tomcat服务停止而销毁),用的时候从内存中读取就相当于缓存了,但是这么做有利也有弊。

好处:操作方便,随时取,随时存,只要方法封装好,代码也很清晰,易扩展。

弊端:因为只要一重启服务器,放在内存中的静态集合或静态数组肯定被回收了。导致一些重要的数据被干掉了。

话题扯远了,本文所讲的就是如何在spring 加载完毕后监听它的事件,并且保证只初始化一次。

配置其实很简单,如下:

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> <!-- 初始化引擎使用 -->
<bean id="InitDataListener" class="cfs.wsdl.cache.InitDataListener">
<property name="dao">
<ref bean="commonBaseDaoHib" />
</property>
</bean> </beans>

spring配置文件

 package cfs.wsdl.cache;

 import java.util.Date;
import java.util.List;
import java.util.UUID; import org.springframework.beans.factory.InitializingBean; import com.google.gson.JsonObject;
import cfs.core.dao.CommonBaseDao; public class InitDataListener implements InitializingBean { private CommonBaseDao dao; public CommonBaseDao getDao() {
return dao;
} public void setDao(CommonBaseDao dao) {
this.dao = dao;
} @Override
public void afterPropertiesSet() throws Exception {
//将需要缓存的数据从数据库里缓存到内存中 //启动一个线程线程:
new Thread() {
public void run() {
while (true) {
try { //这里写一些需要定时执行的代码 //休眠30分钟,半个小时执行一次
Thread.sleep(60 * 1000*30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
}.start(); } }

监听的事件类

监听spring加载完成后事件的更多相关文章

  1. jQuery学习(监听DOM加载)

    jQuery的extend方法 function njQuery() { } /* njQuery.extend = function (obj) { // 此时此刻的this就是njQuery这个类 ...

  2. js - 预加载+监听图片资源加载制作进度条

    这两天遇到一个新需求:一个一镜到底的h5动画.因为功能的特殊性,就要求我们提前监听页面的静态图片是否全部加载完毕.即处理预加载. 总结下来,下次这种需求需要提前注意以下几点: 一.图片而不是背景图 本 ...

  3. C# NanUI WinFormium监听页面加载开始\结束

    个人博客 地址:https://www.wenhaofan.com/article/20190501213608 因为NanUI文档中仅介绍了Formium窗口的监听,但是没有WinFormium相关 ...

  4. iOS-WKWebview 带有进度条加载的ViewController【KVO监听Webview加载进度】

    前言 为什么要说 WKWebview,在之前做电子书笔记时已经提过 WKWebview 在iOS8之后已完全替代 Webview,原因就不多说了,主要还是内存过大: 封装 封装一个基于 UIViewC ...

  5. Android中监听webview监听是否加载完成

    之前写过一篇捕获Phoengap的webview事件的方法,主要是在实现了CordovaInterface的Activity中,  在onMessage中根据第一个参数的message name来判断 ...

  6. 监听iframe加载完成

    用 @load="loading" 在Vue里面写了一个界面,有一个iframe标签, iframe加载其他网站, <iframe @load="loading&q ...

  7. 控制dom 加载成功后事件

  8. AngularJS监听DOM加载完毕

    直接上代码: Module.directive('renderFinish', function ($timeout) { //renderFinish自定义指令 return { restrict: ...

  9. 在应用中显示的图片很多情况不满足业务需求,我们需要动态根据图片的宽高进行缩放或加载中显示的缺省图片,这是我没就需要监听图片加载完成回调,来看看微信小程序怎么实现图片加载完成回调。

    <swiper-item> <image src="{{item.image}}" class="slide-image" mode=&quo ...

随机推荐

  1. Hadoop第13周练习—HBase作业

    1    :举例子说明HBase相对简单 1.1 1.2     回答 2    :设计HBase存储站内短信 2.1 2.2     回答 书面作业1:举例子说明HBase相对简单 请举出一例子,使 ...

  2. Direct3D11学习:(九)绘制基本几何体

    转载请注明出处:http://www.cnblogs.com/Ray1024 一.概述 Direct3D中很多复杂的几何效果都是由基本的几何体组合而成的,这篇文章中,我们来学习集中常见的基本几何体的绘 ...

  3. (非妙味3):浏览器window事件:及浏览各种尺寸介绍

    (触发)window.onload;  window.onscroll;   window.onresize; (兼容)网页可视区尺寸.网页全文尺寸.滚动距离 (实例)广告块高度动态居中.回到顶部   ...

  4. Python 的字符串格式化和颜色控制

    (部分内容源自武神博客和网络收集.) Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两 ...

  5. 餐厅到店点餐系统(APP)

    MY-HR 成员: 角色分配 学号 博客园 丘惠敏 PM项目经理 201406114203 http://www.cnblogs.com/qiuhuimin/ 郭明茵 用户 201406114204 ...

  6. struts2 s:if标签以及 #,%{},%{#}的使用方法

    <s:if>判断字符串的问题: 1.判断单个字符:<s:if test="#session.user.username=='c'"> 这样是从session ...

  7. Python 3.x自定义迭代器对象

    Python 3.x与Python 2.x之间存在着较多的语法细节差异.今天在看Python核心编程的时候,说到了自定义迭代器对象.于是动手将源码打了一遍,原书代码如下: class AnyIter( ...

  8. 模拟浏览器搜索功能(Ctrl + F)

    写的匆忙,示意一下,有待完善.把以下代码复制到文本文件中,把文件扩展名改为.html就可以运行了. <html> <head> <style type="tex ...

  9. .net reflector激活

    1.断网 2. 运行.NET Reflector,点击Help -> Activate 3. 运行注册机,复制注册机生成的序列号,粘贴到.NET Reflector中的激活输入框 4. 点击激活 ...

  10. 【jQuery基础学习】12 jQuery学习感想

    学习完<锋利的jQuery>,用时13天. 这期间,私底下又用了一点时间去W3C上把HTML和CSS重新过了一遍. 总的来说,收获还是蛮多的. 其实在本书里面真正重要的也就前几章,后面的都 ...