如何将LdapConnectionPool与VirtualListViewControl结合使用?
如何将LdapConnectionPool与VirtualListViewControl结合使用?
我先梳理下目前遇到的情况和观察到的关键点:
- 使用
VirtualListViewControl时,必须复用同一个LdapConnection才能保证功能正常。 - 使用
LdapConnectionPool的话,没办法指定获取某一个特定的连接。
我研究了LdapConnectionPool的实现逻辑,发现连接池会把连接交付给客户端,客户端完成操作后必须调用:
connectionPool.releaseConnection(con)
在调用这个方法之前,该连接不会被归还到池中供其他客户端使用。
而对于VirtualListViewControl,我需要维护一个cookieid到LdapConnection的映射关系。用户可能会长时间滚动列表,要是一直占用着连接,感觉有点浪费资源;但如果在第一次请求后就释放连接,那后续用户滚动的时候,这个LDAPConnection可能会被其他线程同时使用。
不过从Java文档来看,这种并发使用的方式是安全的:
/**
...
- This class is mostly threadsafe. It is possible to process multiple
- concurrent operations over the same connection as long as the methods being
- invoked will not change the state of the connection in a way that might
- impact other operations in progress in unexpected ways. In particular, the
- following should not be attempted while any other operations may be in
- progress on this connection:
return (<UL> )return (<LI> )Using one of the {@code connect} methods to re-establish the connection.return (<LI> )Using one of the {@code close} methods to terminate the connection.return (<LI> )Using one of the {@code bind} methods to attempt to authenticate theconnection (unless you are certain that the bind will not impact theidentity of the associated connection, for example by including theretain identity request control in the bind request if using theLDAP SDK in conjunction with a Ping Identity, UnboundID, orNokia/Alcatel-Lucent 8661 Directory Server).return (<LI> )Attempting to make a change to the way that the underlying communicationis processed (e.g., by using the StartTLS extended operation to convertan insecure connection into a secure one).**/
@ThreadSafety(level=ThreadSafetyLevel.MOSTLY_THREADSAFE)
public final class LDAPConnection
implements FullLDAPInterface, LDAPConnectionInfo, ReferralConnector,
Closeable
{
但奇怪的是,LdapConnectionPool非要等到连接被释放才会把它重新分配出去。所以我想请教下,把LdapConnectionPool和VirtualListViewControl结合使用的话,最优的方式是什么?
备注:内容来源于stack exchange,提问作者gstackoverflow
相关产品推荐
相关产品推荐

