You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将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 the
    
  • connection (unless you are certain that the bind will not impact the
    
  • identity of the associated connection, for example by including the
    
  • retain identity request control in the bind request if using the
    
  • LDAP SDK in conjunction with a Ping Identity, UnboundID, or
    
  • Nokia/Alcatel-Lucent 8661 Directory Server).
    
  • return (<LI>
    )
  • Attempting to make a change to the way that the underlying communication
    
  • is processed (e.g., by using the StartTLS extended operation to convert
    
  • an 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:29:49