开发者

connection pool for proprietary connection api (non jdbc)

开发者 https://www.devze.com 2023-02-24 07:34 出处:网络
I am using an API to connect to some hardware terminals and networks. The API allows me to connect to the servers, disconnect and interrogate for data, pretty similar to what JDBC connection allows yo

I am using an API to connect to some hardware terminals and networks. The API allows me to connect to the servers, disconnect and interrogate for data, pretty similar to what JDBC connection allows you to do. Anyway, since this is not using the JDBC Connection interface, I cannot use a connection pooling already existing. I would like to avoid writing one myself if I can use one already existing, or maybe just build a small adapter on top of that. Anyone knows of any framework/library that would allow me to enable connection pooling, that can handle my connections, can ensure that the connection is alive all the time etc?

I have looked at Commons Pool, but that only gives you a few classes to put/get your connecti开发者_高级运维ons ... it doesn't do any of the maintenance tasks etc (check if connection is invalid from time to time, reconnect etc). I can add on top of that the mechanism of connection checking and reconnecting if any issues etc in case there is nothing out there that does this already.

Cheers, Stef.


Apache Commons Pool actually supports creating, destroying and checking objects for validity before handing them out with the PoolableObjectFactory class, which you use with the actual pool implementation by passing it as a parameter:

final PoolableObjectFactory objectFactory = new MyPoolableObjectFactoryImpl();
final ObjectPool pool = new GenericObjectPool(objectFactory);


You can look into dbcp http://commons.apache.org/dbcp/

it's BasicDataSource provide methods such as maxActive, maxIdle, maxWait etc check documentation for more http://commons.apache.org/dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html

interesting one if you are going for new implementation try tomcat 7 jdbc connection pool http://people.apache.org/~fhanik/jdbc-pool/jdbc-pool.html

[edit] useless for the scenario -hGx so upvoting Henning's post

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号