Network-Attached Memory(HAM)terracotta笔记(三)

Network-Attached Memory(HAM)terracotta笔记(三)

run webapplication under tomcat in ubuntu system

1.cluster hashmap in my bean
modify the bean ClusterManagerImpl.java like this:
package com.sillycat.manager.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.sillycat.api.commons.base.BaseManager;
import com.sillycat.manager.ClusterManager;
import com.sillycat.model.User;

public class ClusterManagerImpl extends BaseManager implements ClusterManager {

public final Object lock = new Object();

private Map usersMap = new HashMap();

private int count = 0;

public int getCount() {
return count;
}

public void addCount() {
synchronized (lock) {
count++;
}
}

public void putUser(User user) {
synchronized (lock) {
usersMap.put("USER_" + user.getId(), user);
}
}

public List<User> getUsers() {
List<User> list = null;
if (usersMap != null && !usersMap.isEmpty()) {
list = new ArrayList<User>(usersMap.size());
Iterator it = usersMap.keySet().iterator();
for(;it.hasNext();){
String key = (String)it.next();
User user = (User)usersMap.get(key);
list.add(user);
}
}
return list;
}
}

modify the tc-config.xml to cluster the class User and BaseObject add instrumented-classes between <jee-application name="easySearch"></jee-application>

<instrumented-classes>
<include>
<class-expression>com.sillycat.model.User</class-expression>
</include>
<include>
<class-expression>com.sillycat.api.commons.base.BaseObject</class-expression>
</include>
</instrumented-classes>

2.config the tomcat server
just do what we do to config on the windows system
copy the configration from the $TERRACOTTA_HOME/samples/spring/jmx
and then modify the file /usr/local/terracotta-2.6.4/samples/easy/search/tomcat1/conf/Catalina/localhost/easySearch.xml:

<Context path="/easySearch" docBase="/usr/local/terracotta-2.6.4/samples/easy/search/webapps/easySearch.war"
debug="0" privileged="true">
</Context>

put the easySearch.war and tc-config.xml in the right way

start the tomcat server
./start-tomcat1.sh &
./start-tomcat2.sh &
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值