约定
本文的实现环境是
hibernate 3.3.1
WebSphere 6.1.0.21
其他版本应该可以有相同或类似路径和实现方式(具体请查看其用户手册)
具体步骤
http://serverIP:9060/ibm/console
资源 ==> 高速缓存实例 ==> 对象高速缓存实例
名称: HibernateCache
JNDI名称: services/cache/hibernate
高速缓存大小: 20000(根据需要而定)
缺省优先级别:1
- 应用并保存到主配置
- 创建hibernate 的Cache实现类
package com.achievo.framework.cache;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.cache.Cache;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.Timestamper;
import com.ibm.websphere.cache.DistributedMap;
/*
* @author xhm(hyamine)
*/
public class AchievoCache implements Cache {
private final DistributedMap distMap;
private final String regionName;
public AchievoCache(DistributedMap distMap,String regionName) {
this.distMap = distMap;
this.regionName = regionName;
}
public void clear() throws CacheException {
distMap.clear();
}
public void destroy() throws CacheException {
}
public Object get(Object key) throws CacheException {
return distMap.get(key);
}
public long getElementCountInMemory() {
return distMap.size();
}
public long getElementCountOnDisk() {
return 0;
}
public String getRegionName() {
return regionName;
}
public long getSizeInMemory() {
return -1;
}
public int getTimeout() {
return Timestamper.ONE_MS * 60000; //ie. 60 seconds
}
public void lock(Object key) throws CacheException {
}
public long nextTimestamp() {
return Timestamper.next();
}
public void put(Object key, Object value) throws CacheException {
distMap.put(key, value);
}
public Object read(Object key) throws CacheException {
return distMap.get(key);
}
public void remove(Object key) throws CacheException {
distMap.remove(key);
}
public Map toMap() {
return Collections.unmodifiableMap(distMap);
}
public void unlock(Object key) throws CacheException {
}
public void update(Object key, Object value) throws CacheException {
put(key, value);
}
public String toString() {
return "DistributedMap(" + regionName + ')';
}
}
- 创建hibernate的CacheProvider实现类
package com.achievo.framework.cache;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.hibernate.cache.Cache;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.CacheProvider;
import org.hibernate.cache.Timestamper;
import com.ibm.websphere.cache.DistributedMap;
/*
* @author xhm(hyamine)
*/
public class AchievoCacheProvider implements CacheProvider{
private static DistributedMap distMap;
public Cache buildCache(String regionName, Properties properties)
throws CacheException {
if(distMap == null) {
try {
distMap = (DistributedMap)new InitialContext().lookup("java:comp/env/cache/hibernate");
} catch (NamingException e) {
e.printStackTrace();
throw new CacheException(e);
}
}
return new AchievoCache(distMap,regionName);
}
public boolean isMinimalPutsEnabledByDefault() {
return false;
}
public long nextTimestamp() {
return Timestamper.next();
}
public void start(Properties properties) throws CacheException {
}
public void stop() {
}
}
hibernate.cache.use_second_level_cache ==> true
hibernate.cache.provider_class ==> com.achievo.framework.cache.AchievoCacheProvider
ibm-web-bnd.xmi
<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1237946146690" virtualHostName="default_host">
<webapp href="WEB-INF/web.xml#WebApp_1237946146690"/>
<resRefBindings xmi:id="ResourceRefBinding_1238122581168" jndiName="services/cache/hibernate">
<bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1238122581168"/>
</resRefBindings>
</webappbnd:WebAppBinding>
web.xml
<resource-ref id="ResourceRef_1238122581168">
<res-ref-name>cache/hibernate</res-ref-name>
<res-type>com.ibm.websphere.cache.DistributedMap</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
参考文献
- http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html
- http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.base.doc/info/aes/ae/tdyn_distmap.html
分享到:
相关推荐
利用IBM WAS中间件特性,实现分布式缓存和服务器间的数据共享。 利用IBM WAS的 DistributedMap 数据对象。 虽然“中间件依赖”是不被提倡的,但是它简单高效啊。 简单的操作就能带给我们飞一般的性能体验,不需要...
介绍这是一个利用以下技术的示例项目: WebSphere应用服务器8.5 JPA 2.0 冬眠SpringMVC 该项目的目的仅仅是演示如何集成这些技术。 有关更多信息,请查看我的博客文章, 为: : 项目准备参见doc / 0001_InitialDdl....
使用WebSphere MQ管理远程队列管理器.doc
Websphere MQ实现应用程序通信
websphere commerce的使用即websphere commerce图解.在网上扒了半天才找到的稀品啊!IBM创建商品店铺(websphere commerce).pdf 一些其他的相关资料: ...
本人自学IBM的WebSphereMQ自学笔记,内有MQ安装文档,建MQ的例子等。 1、 MQ6.0安装 2 1.1 启动MQ v6.0 安装程序 2 1.2 软件需求检查 2 1.3 WebSphere Eclipse Platform V3.0.1软件安装 2 1.4 网络配置检查 3 1.5 ...
* 给分布式处理提供的强健的中间件:WebSphere MQ 可以提供强健的中间件,支持分布式处理。 WebSphere MQ 的应用场景 WebSphere MQ 可以应用于各种需要异步通信的场景,例如: * 订单处理系统:WebSphere MQ 可以...
4.2 使用命令管理 WebSphere MQ 51 4.2.1控制命令 52 4.2.2WebSphere MQ 脚本(MQSC)命令 52 4.2.3PCF 命令 54 4.3 WebSphere MQ 配置 56 4.3.1在 Windows 系统上更改配置信息 56 4.3.2 在 UNIX 系统上更改配置信息...
WebSphere7使用手册 WebSphere7使用手册
* 异步通信:使用Websphere MQ来实现异步通信,提高系统的可扩展性和可维护性 * 消息队列系统:使用Websphere MQ来实现消息队列系统,管理和处理大量的消息 Websphere MQ的Java API Websphere MQ提供了一个Java ...
配置WAS缓存后,可在应用发布或者更新消息时人为的进行缓存读取与清除
webSphere指南webSphere指南webSphere指南webSphere指南webSphere指南
JSF 组件WebSphere 平台配置使用说明
* 提高业务效率:WebSphere MQ 可以实现业务自动化,提高企业的业务效率和生产力。 * 降低IT成本:WebSphere MQ 可以降低企业的 IT 成本,提高投资回报率。 * 提高业务灵活性:WebSphere MQ 可以帮助企业快速响应...
-- 实现应用基础架构层面的虚拟化 WebSphere Virtual Enterprise 核心功能 完整的企业级应用虚拟运行环境 •应用基础架构虚拟化 •应用程序分服务级别的响应 •智能的动态资源管理 自动化的感知响应管理 •多...
学习使用WebSphere MQ for Java编程。 WebSphere MQ for Java允许用Java 编程语言写成的程序直接访问WebSphere MQ Server,或作为一个WebSphere MQ Client连接到WebSphere MQ。
一个C#实现IBM WebSphere MQ 消息收发的实例,包含 发送接收等. 使用的时候只需要修改 appconfig 文件的内容即可. 如有问题.请留言
WebSphere
包括了WebSphere中缓存、日志、配置等常用地址
websphere设计