how implement jedis without jedispool/commons-pool2-2.0 because still using jdk 1.5(commons-pool2-2.0 not support jdk 1.5)
how implement thread-safe connection pooling?
i'm not sure jedis compatibility java 5. can create own pooling based on older commons-pool 1.6 library. not need have commons-pool2 on class path run jedis. used jedis 2.7.3 , commons-pool 1.6 validate solution approach.
find example code attached:
import org.apache.commons.pool.objectpool; import org.apache.commons.pool.poolableobjectfactory; import org.apache.commons.pool.impl.genericobjectpool; import redis.clients.jedis.jedis; public class jediswithownpooling { public static void main(string[] args) throws exception { objectpool<jedis> pool = new genericobjectpool(new jedisfactory("localhost")); jedis j = pool.borrowobject(); system.out.println(j.ping()); pool.returnobject(j); pool.close(); } private static class jedisfactory implements poolableobjectfactory<jedis> { private string host; /** * add fields need. that's example. */ public jedisfactory(string host) { this.host = host; } @override public jedis makeobject() throws exception { return new jedis(host); } @override public void destroyobject(jedis jedis) throws exception { jedis.close(); } @override public boolean validateobject(jedis jedis) { return jedis.isconnected(); } @override public void activateobject(jedis jedis) throws exception { if (!jedis.isconnected()) { jedis.connect(); } } @override public void passivateobject(jedis jedis) throws exception { } } }
Comments
Post a Comment