Spring集成memcached的详细介绍
前提条件:工程需要引入jar包java_memcached-release_2.0.1.jar
第一步:添加memcached的配置文件。
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="false" />
<property name="locations">
<list>
<value>classpath:memcache.properties</value>
</list>
</property>
</bean>
配置文件内容如下:
memcache.server=xxx.xxx.xxx.xxx:11111
memcache.weights=1
memcache.initConn=1
memcache.minConn=1
memcache.maxConn=50
memcache.maintSleep=3000
memcache.nagle=false
memcache.socketTO=3000
第二步:添加memcached的bean管理。
<bean id="memcachedPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance"
init-method="initialize" destroy-method="shutDown">
<constructor-arg><value>memCachedPool</value></constructor-arg>
<property name="servers"><list><value>${memcache.server}</value></list></property>
<property name="weights"><list><value>${memcache.weights}</value></list></property>
<property name="initConn"><value>${memcache.initConn}</value></property>
<property name="minConn"><value>${memcache.minConn}</value></property>
<property name="maxConn"><value>${memcache.maxConn}</value></property>
<property name="maintSleep"><value>${memcache.maintSleep}</value></property>
<property name="nagle"><value>${memcache.nagle}</value></property>
<property name="socketTO"><value>${memcache.socketTO}</value></property>
</bean>
下面看一下com.danga.MemCached.SockIOPool的源代码,重点是SockIOPool构造函数:
public static synchronized SockIOPool getInstance(String poolName)
{
if (pools.containsKey(poolName))
return pools.get(poolName);
SockIOPool pool = new SockIOPool();
pools.put(poolName, pool);
return pool;
}
<bean id="memCacheClient" class="com.danga.MemCached.MemCachedClient">
<constructor-arg><value>memCachedPool</value></constructor-arg>
</bean>
下面看一下com.danga.MemCached.MemCachedClient的源代码,重点是MemCachedClient的构造函数:
public MemCachedClient(String poolName)
{
this.poolName = poolName;
init();
}
第三步:测试memcached的功能。
public class MemcacheTest {
public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
MemCachedClient memCachedClient=(MemCachedClient)context.getBean("memCacheClient");
memCachedClient.set("hello", "swiftlet");
memCachedClient.get("hello");
}
}
Spring集成memcached的详细介绍的更多相关文章
- 从零开始学 Java - Spring 集成 Memcached 缓存配置(一)
硬盘和内存的作用是什么 硬盘的作用毫无疑问我们大家都清楚,不就是用来存储数据文件的么?如照片.视频.各种文档或等等,肯定也有你喜欢的某位岛国老师的动作片,这个时候无论我们电脑是否关机重启它们永远在那里 ...
- 从零开始学 Java - Spring 集成 Memcached 缓存配置(二)
Memcached 客户端选择 上一篇文章 从零开始学 Java - Spring 集成 Memcached 缓存配置(一)中我们讲到这篇要谈客户端的选择,在 Java 中一般常用的有三个: Memc ...
- struts2 + spring + mybatis 框架整合详细介绍
struts2 + spring + mybatis 框架整合详细介绍 参考地址: https://blog.csdn.net/qq_22028771/article/details/5149898 ...
- (2)Spring集成Quartz定时任务框架介绍和Cron表达式详解
在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等.我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作,但 ...
- Spring集成Quartz定时任务框架介绍和Cron表达式详解
原文地址:http://www.cnblogs.com/obullxl/archive/2011/07/10/spring-quartz-cron-integration.html 在JavaEE系统 ...
- Spring集成Quartz定时任务框架介绍
在JavaEE系统中,我们会经常用到定时任务,比如每天凌晨生成前天报表,每一小时生成汇总数据等等.我们可以使用java.util.Timer结合java.util.TimerTask来完成这项工作,但 ...
- Spring 相关jar包详细介绍
文章转自:http://blog.csdn.net/farawayhome/article/details/6623946 aspectj目录下是在Spring框架下使用aspectj的源代码和测试程 ...
- Spring集成Memcached三种方式(一)
转载:http://blog.csdn.net/u013725455/article/details/52102170 Memcached Client目前有3种: Memcached Client ...
- Spring @Component的作用详细介绍
@component 作用 1.@controller 控制器(注入服务)2.@service 服务(注入dao)3.@repository dao(实现dao访问)4.@component (把普通 ...
随机推荐
- hive DDL
官网地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL https://cwiki.apache.org/co ...
- JSON Web Token
What is JSON Web Token? JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact a ...
- C# WPF定时器
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来.我们都知道计算机技术发展日新月异,速度惊人的快,你我稍不留神,就会被慢慢淘汰!因此:每日不间断的学习是避免被 ...
- checkbox判断选中
$("input[type='checkbox']").is(':checked')
- c#操作Excel时,抛出异常:“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”
我们开发环境下,使用excel导入数据到数据库中,编译的软件起初是x86 方式,起初并未发现什么问题,一切很正常: 程序该进的过程: 后来导入文件一次就要读取几百G的数据导入数据库中,使用编译的X86 ...
- 链表操作,空间复杂度要求为O(1)
对于O(1)的空间复杂度要求,不能对链表进行复制等操作,双指针法对处理该类问题比较有效. 同时由于链表头结点的特殊性,可以考虑引入一个空的头结点来辅助操作.
- tableview在第一次显示时会自动relodata
tableview在第一次显示时会自动加载数据
- sublime text常用插件
这个比较重要,不会装插件的时候找了好久 sublime text常用插件 1.插件的安装方法 第一种:用package control 这个是用来管理插件的,必备啊,安装package control ...
- 使用Navicat for Oracle新建表空间、用户及权限赋予---来自烂泥
Navicat for Oracle是有关Oracle数据库的客户端工具.通过这个客户端,我们可以图形方式对Oracle数据库进行操作. 说 明我们此次试验的Oracle数据库版本是Oracle 10 ...
- Regist
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\Current ...