java - error in Using netty with jedis -


i'm using netty , redis (jedis client), , in each request query method of redisdb call, when test in apache benchmarking command

ab -c 10 -n 10 localhost:2080

the below error occurs.

    mar 10, 2014 3:29:48 pm io.netty.channel.defaultchannelpipeline$tailhandler exceptioncaught warning: exceptioncaught() event fired, , reached @ tail of pipeline. means last handler in pipeline did not handle exception. java.lang.nullpointerexception     @ redis.clients.jedis.protocol.sendcommand(protocol.java:39)     @ redis.clients.jedis.protocol.sendcommand(protocol.java:33)     @ redis.clients.jedis.connection.sendcommand(connection.java:80)     @ redis.clients.jedis.binaryclient.append(binaryclient.java:200)     @ redis.clients.jedis.client.append(client.java:125)     @ redis.clients.jedis.jedis.append(jedis.java:616)     @ com.kdgames.server.asyncdatabase.redisdb.query(redisdb.java:14)     @ serverinboundhandler.channelread0(serverinboundhandler.java:41)     @ serverinboundhandler.channelread0(serverinboundhandler.java:1)     @ io.netty.channel.simplechannelinboundhandler.channelread(simplechannelinboundhandler.java:103)     @ io.netty.channel.defaultchannelhandlercontext.invokechannelread(defaultchannelhandlercontext.java:340)     @ io.netty.channel.defaultchannelhandlercontext.firechannelread(defaultchannelhandlercontext.java:326)     @ io.netty.channel.channelinboundhandleradapter.channelread(channelinboundhandleradapter.java:86)     @ io.netty.channel.defaultchannelhandlercontext.invokechannelread(defaultchannelhandlercontext.java:340)     @ io.netty.channel.defaultchannelhandlercontext.firechannelread(defaultchannelhandlercontext.java:326)     @ io.netty.handler.codec.messagetomessagedecoder.channelread(messagetomessagedecoder.java:103)     @ io.netty.channel.defaultchannelhandlercontext.invokechannelread(defaultchannelhandlercontext.java:340)     @ io.netty.channel.defaultchannelhandlercontext.firechannelread(defaultchannelhandlercontext.java:326)     @ io.netty.handler.codec.bytetomessagedecoder.channelread(bytetomessagedecoder.java:155)     @ io.netty.channel.defaultchannelhandlercontext.invokechannelread(defaultchannelhandlercontext.java:340)     @ io.netty.channel.defaultchannelhandlercontext.firechannelread(defaultchannelhandlercontext.java:326)     @ io.netty.channel.defaultchannelpipeline.firechannelread(defaultchannelpipeline.java:785)     @ io.netty.channel.nio.abstractniobytechannel$niobyteunsafe.read(abstractniobytechannel.java:116)     @ io.netty.channel.nio.nioeventloop.processselectedkey(nioeventloop.java:494)     @ io.netty.channel.nio.nioeventloop.processselectedkeysoptimized(nioeventloop.java:461)     @ io.netty.channel.nio.nioeventloop.processselectedkeys(nioeventloop.java:378)     @ io.netty.channel.nio.nioeventloop.run(nioeventloop.java:350)     @ io.netty.util.concurrent.singlethreadeventexecutor$2.run(singlethreadeventexecutor.java:101)     @ java.lang.thread.run(unknown source) 

and here code

public class redisdb {     jedis jedis;      public redisdb() {         jedis = new jedis("192.168.56.101", 6179);     }      public void query() {          jedis.append("foo", "bar");       } } 

rather wild guess: in multithreaded environment should use connection pool as described in jedis documentation.

the code like:

public class redisdb {     jedispool pool;      public redisdb() {         pool = new jedispool(new jedispoolconfig(), "192.168.56.101", 6179)     }      public void query() {         jedis jedis = pool.getresource();         try {             jedis.append("foo", "bar");          } catch (jedisconnectionexception e) {             // returnbrokenresource when state of object unrecoverable             if (null != jedis) {                 pool.returnbrokenresource(jedis);                 jedis = null;             }         } {           /// ... it's important return jedis instance pool once you've finished using           if (null != jedis)             pool.returnresource(jedis);         }     } } 

and don't forget close connections when closing application:

pool.destroy(); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -