Terracotta Discussion Forums
Search
Recent Topics
Member Listing
Back to home page
Register
/
Login
tomcat在执行cache.put(element);时崩溃
Forum Index
->
Terracotta 中文社区
Author
Message
07/04/2012 23:32:55
Subject:
tomcat在执行cache.put(element);时崩溃
dancer82
neo
Joined: 07/04/2012 21:24:53
Messages: 5
Offline
我使用的terracotta版本是: 3.5.2 ehcache.xml 为这样:
<cache name="forums" maxElementsInMemory="1000000" eternal="true"
timeToIdleSeconds="10800" timeToLiveSeconds="10800" maxElementsOnDisk="500000"
overflowToDisk="false">
<terracotta />
</cache>
发生故障前,java code为:
public void set(Object key, Object value) {
try {
cache.acquireWriteLockOnKey(MobcentConstants.FORUM_CACHE_KEY);
Element element = new Element(key, value);
if (cache != null)
cache.put(element);
else
LogService.errorSystemLog(cacheError);
} finally {
cache.releaseWriteLockOnKey(MobcentConstants.FORUM_CACHE_KEY);
}
}
上周,服务器宕机了,随机,我用java的remote debug连上服务器,看见了问题是:
程序执行到cache.put(element);的时候,便不会再往下执行,这时,如果另外一个线程进来的话,便会一起等待。线程多了,导致死机
同时,会因为auto commit = false 死锁mysql,linux系统狂抛"Too many open file".这些都是后话
于是,我清理了terracotta的文件,包括tomcat下的temp文件夹和
<data>/usr/local/terracotta/s45-data</data>
<logs>/usr/local/terracotta/s45-logs</logs>
<statistics>/usr/local/terracotta/s45-statistics</statistics>
这几个文件夹
改变了一下ehcache.xml
<cache name="forums" maxElementsInMemory="1000000" eternal="false" <== true改成了false
timeToIdleSeconds="10800" timeToLiveSeconds="10800" maxElementsOnDisk="500000"
overflowToDisk="false">
<terracotta />
</cache>
改了java code:
public void set(Object key, Object value) {
Element element = new Element(key, value);
if (cache != null)
cache.put(element);
else
LogService.errorSystemLog(cacheError);
}
这个方法中,删除了acquireWriteLockOnKey和releaseWriteLockOnKey。
重启了数据库,缓存,设置了"ulimit -n 10240"后,系统恢复了正常。
程序设计的其他部分出错的概率较小。虽然系统恢复了正常,单单对于这个put操作,我想问一下:
1.这个死锁是否来自于cache.acquireWriteLockOnKey(MobcentConstants.FORUM_CACHE_KEY);
2.MobcentConstants.FORUM_CACHE_KEY是一个常量,可能我是用错了,是否该是使用cache.acquireWriteLockOnKey(key); key为一个变量
3.如果cache.acquireWriteLockOnKey(MobcentConstants.FORUM_CACHE_KEY);然后又解开了,是不是等同于直接cache.put(element); 如果等同于,是否意味着我现在的程序
还可能有下次的死机
4.我改了配置和java code以后,按照现在的写法和配置,还会有崩溃的现象产生么?
07/05/2012 00:04:56
Subject:
Re:tomcat在执行cache.put(element);时崩溃
rajoshi
seraphim
Joined: 07/04/2011 04:36:10
Messages: 1465
Offline
Hi,
Can you please post your issue in English.
Rakesh Joshi
Terracotta.
07/05/2012 00:08:08
Subject:
Re:tomcat在执行cache.put(element);时崩溃
dancer82
neo
Joined: 07/04/2012 21:24:53
Messages: 5
Offline
Hi,
here is my english topic, the same content:
http://forums.terracotta.org/forums/posts/list/7181.page
Forum Index
->
Terracotta 中文社区
Go to:
Select a forum
BigMemory
Ehcache
General
Quartz
BigMemory + Hadoop
Terracotta for Web Sessions
Terracotta Platform
Terracotta Licensing
Terracotta 中文社区
Terracotta for Spring
Powered by
JForum 2.1.7
©
JForum Team