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 (把普通 ...
随机推荐
- 在centos安装docker
关闭防火墙 iptables -L systemctl disable firewalld.service systemctl stop firewalld.service 配置代理太麻烦了,建议使用 ...
- uiwebview加载中文URL
uiwebview加载中文URL _paperGamePath = [_paperGamePath stringByAddingPercentEscapesUsingEncoding:NSUTF8St ...
- 当数据库某张表数据发生变化时,更新c#程序中缓存的用法
参考:http://www.webkaka.com/tutorial/asp.net/2012/111912/(SqlDependency和SqlCacheDependency缓存的用法及具体步骤) ...
- jquery垂直展开折叠手风琴二级菜单
摘要:jquery实现垂直展开二级菜单 最近新开发一个简单项目,用到左侧两级的菜单.找找了手头的文件,竟然没有现成的代码,算了,去网上找找整理下吧. 注:jquery-1.8.3.min.js需要下载 ...
- Leetcode: Graph Valid Tree && Summary: Detect cycle in undirected graph
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- navicat内的主键和外键
数据库内的一个重点是主键另一个是外键 实体完整性{ 主键的全称:主关键字 它能够进行唯一标示某一列的 主键的三大特点是:唯一 非空 排序 一个没有主键的表不是一个完整的表,只要表设置了主键那 ...
- java BigInteger
用Java来处理高精度问题,相信对很多ACMer来说都是一件很happy的事,简单易懂.用Java刷了一些题,感觉Java还不错,在处理高精度和进制转换中,调用库函数的来处理.下面是写的一些Java中 ...
- hdu4609 3-idiots
FFT 代码 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> ...
- snmp getTable demo :iftable ipAddresstable
package org.huangxf.snmp.test; import java.io.IOException; import java.util.List; import org.snmp4j. ...
- JAVA实现File类中的遍历操作并输出内容
package shb.java.testIo; import java.io.BufferedReader; import java.io.BufferedWriter; import java.i ...