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 &
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 &

被折叠的 条评论
为什么被折叠?



