| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5295 人关注过本帖
标题:memcatched遇到个问题,求大神指点
只看楼主 加入收藏
leonardo38
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2009-1-1
结帖率:20%
收藏
 问题点数:0 回复次数:0 
memcatched遇到个问题,求大神指点
memcatched类里面:
public class MemcachedUtil {

        /**
         * memcached客户端单例
         */
        private static MemCachedClient cachedClient = new MemCachedClient();
        
        /**
         * 初始化连接池
         */
        static {
            //获取连接池的实例
            SockIOPool pool = SockIOPool.getInstance();

            //服务器列表及其权重
            String[] servers = {"127.0.0.1:11211"};
            Integer[] weights = {3};

            //设置服务器信息
            pool.setServers(servers);
            pool.setWeights(weights);

            //设置初始连接数、最小连接数、最大连接数、最大处理时间
            pool.setInitConn(10);
            pool.setMinConn(10);
            pool.setMaxConn(1000);
            pool.setMaxIdle(1000*60*60);
            
            //设置连接池守护线程的睡眠时间
            pool.setMaintSleep(60);
            
            //设置TCP参数,连接超时
            pool.setNagle(false);
            pool.setSocketTO(60);
            pool.setSocketConnectTO(0);

            //初始化并启动连接池
            pool.initialize();
            
            //压缩设置,超过指定大小的都压缩
//          cachedClient.setCompressEnable(true);
//          cachedClient.setCompressThreshold(1024*1024);
        }
         
        private MemcachedUtil(){
        }
        
        //添加一个值,如果已经存在,则返回false
        public static boolean add(String key, Object value) {
            return cachedClient.add(key, value);
        }
         
        //添加一个值,如果已经存在,则返回false ,参数expire为存储值的过期时间,如果为0表示不会过期,你可以用unix时间戳或者描述来表示从现在开始的时间,但是你在使用秒数表示的时候,不要超过2592000秒 (表示30天)。
        public static boolean add(String key, Object value, Integer expire) {
            return cachedClient.add(key, value, expire);
        }
        
      //添加一个值,如果已经存在,则覆写
        public static boolean set(String key, Object value) {
            return cachedClient.set(key, value);
        }

      //添加一个值,如果已经存在,则覆写,参数expire为存储值的过期时间,如果为0表示不会过期,你可以用unix时间戳或者描述来表示从现在开始的时间,但是你在使用秒数表示的时候,不要超过2592000秒 (表示30天)。
        public static boolean set(String key, Object value, Integer expire) {
            return cachedClient.set(key, value, expire);
        }
        
        //对一个已有的key进行覆写操作
        public static boolean replace(String key, Object value) {
            return cachedClient.replace(key, value);
        }
        
        //对一个已有的key进行覆写操作,参数expire为存储值的过期时间,如果为0表示不会过期,你可以用unix时间戳或者描述来表示从现在开始的时间,但是你在使用秒数表示的时候,不要超过2592000秒 (表示30天)。
        public static boolean replace(String key, Object value, Integer expire) {
            return cachedClient.replace(key, value, expire);
        }
        
        //删除一个key值
        public static boolean delete(String key) {
            return cachedClient.delete(key);
        }

        //获取一个key值
        public static Object get(String key) {
            return cachedClient.get(key);
        }
    }


memcatched的XML配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.
    xmlns:xsi="http://www.
    xmlns:aop="http://www.
    xmlns:tx="http://www.
    xsi:schemaLocation="
    http://www. http://www.
    http://www. http://www.
    http://www. http://www.


    <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"
        factory-method="getInstance" init-method="initialize">
        <constructor-arg>
            <value>neeaMemcachedPool</value>
        </constructor-arg>
        <property name="servers">
            <list>
                <value>127.0.0.1:11211</value>
            </list>
        </property>
        <property name="initConn">
            <value>20</value>
        </property>
        <property name="minConn">
            <value>10</value>
        </property>
        <property name="maxConn">
            <value>50</value>
        </property>
        <property name="nagle">
            <value>false</value>
        </property>
        <property name="socketTO">
            <value>3000</value>
        </property>
    </bean>
    <bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient">
        <constructor-arg>
            <value>neeaMemcachedPool</value>
        </constructor-arg>
    </bean>
   
    <bean id="memcachedService" parent="baseTransactionProxy">
        <property name="proxyTargetClass" value="true" />
        <property name="target">
            <bean class="service.dms.memcached.MemcachedServiceImpl">
                <property name="dao" ref="userDAO" />
                <property name="dataSource" ref="dataSource" />
                <property name="oumService" ref="oftenUsedMenuService" />
                <property name="systemConfigservice" ref="SystemConfigService" />
            </bean>
        </property>
    </bean>
</beans>


现在的问题是当我开发的时候,如果两个类的服务器连接都使用,保存单个对象的时候没问题,但保存一个用JSON转化成OBJECT的LIST<BEAN>的时候,会报错,报错如下:
1114158 ["http-bio-8080"-exec-9] ERROR com.danga.MemCached.MemCachedClient - ++++ exception thrown while writing bytes to server on set
1114158 ["http-bio-8080"-exec-9] ERROR com.danga.MemCached.MemCachedClient - 远程主机强迫关闭了一个现有的连接。
远程主机强迫关闭了一个现有的连接。
    at sun.nio.ch.SocketDispatcher.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(Unknown Source)
    at sun.nio.(Unknown Source)
    at sun.nio.(Unknown Source)
    at sun.nio.ch.SocketChannelImpl.write(Unknown Source)
    at com.schooner.MemCached.SockOutputStream.writeToChannel(Unknown Source)
    at com.schooner.MemCached.SockOutputStream.write(Unknown Source)
    at com.schooner.MemCached.SockOutputStream.write(Unknown Source)
    at com.schooner.MemCached.AscIIClient.set(Unknown Source)
    at com.schooner.MemCached.AscIIClient.set(Unknown Source)
    at com.danga.MemCached.MemCachedClient.set(Unknown Source)
    at common.memcached.MemcachedUtil.set(MemcachedUtil.java:65)
    at service.dms.memcached.MemcachedServiceImpl.findByHql(MemcachedServiceImpl.java:1051)
    at service.dms.memcached.MemcachedServiceImpl$$FastClassByCGLIB$$cbae0c72.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
    at service.dms.memcached.MemcachedServiceImpl$$EnhancerByCGLIB$$5492a42d.findByHql(<generated>)
    at webapp.action.dms.memcached.MemcachedTestAction.query(MemcachedTestAction.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:421)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:136)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:326)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:313)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at webapp.action.dms.filter.AuthFilter.doFilter(AuthFilter.java:167)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.ecside.filter.ECSideFilter.doFilter(ECSideFilter.java:188)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    at org.apache.tomcat.(JIoEndpoint.java:288)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)


然后如果我把类里面的服务器配置注释了后只保留XML文件的配置运行,不管是保存单个对象还是转化后的LIST的,都会报错,报错如下:
60945 ["http-bio-8080"-exec-5] ERROR com.schooner.MemCached.SchoonerSockIOPool - attempting to get SockIO from uninitialized pool!

求助啊,有没有会memcatched分布式缓存技术的大神在,求指导
搜索更多相关主题的帖子: 服务器列表 private public 客户端 
2013-12-06 17:05
快速回复:memcatched遇到个问题,求大神指点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020318 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved