来源:http://java.sun.com/products/jndi/tutorial/ldap/connect/pool.html

Sample:

import javax.naming.*;

import javax.naming.directory.*;

import java.util.Hashtable;

/**

* Demonstrates how to enable connection pooling. Use debug option

* to observe connection usage.

*

* usage: java -Dcom.sun.jndi.ldap.connect.pool.debug=fine UsePool

*/

class UsePool {

public static void main(String[] args) {

// Set up environment for creating initial context

Hashtable env = new Hashtable(11);

env.put(Context.INITIAL_CONTEXT_FACTORY,

"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");

// Enable connection pooling

env.put("com.sun.jndi.ldap.connect.pool", "true");

try {

// Create one initial context (Get connection from pool)

DirContext ctx = new InitialDirContext(env);

System.out.println(ctx.getAttributes("ou=NewHires"));

// do something useful with ctx

// Close the context when we're done

ctx.close(); // Return connection to pool

// Create another initial context (Get connection from pool)

DirContext ctx2 = new InitialDirContext(env);

System.out.println(ctx2.getAttributes("ou=People"));

// do something useful with ctx2

// Close the context when we're done

ctx2.close(); // Return connection to pool

} catch (NamingException e) {

e.printStackTrace();

}

}

}Creation TimeoutThe pool of connections maintained by the LDAP service provider may be limited in size; this is described in detail in the Connection Pooling Configuration section. When connection pooling has been enabled and no pooled connection is available, the client application will block, waiting for an available connection. You can use the "com.sun.jndi.ldap.connect.timeout" environment property to specify how long to wait for a pooled connection. If you omit this property, the application will wait indefinitely.

This same property is also used to specify a timeout period for establishment of the LDAP connection, as described in the Connection Creation section.

When Not to Use PoolingPooled connections are intended to be reused. Therefore, if you plan to perform operations on a Context instance that might alter the underlying connection's state, then you should not use connection pooling for that Context instance. For example, if you plan to invoke the Start TLS extended operation on a Context instance, or plan to change security-related properties (such as "java.naming.security.principal" or "java.naming.security.protocol") after the initial context has been created, you should not use connection pooling for that Context instance because the LDAP provider does not track any such state changes. If you use connection pooling in such situations, you might be compromising the security of your application.

----------------------------------------------------------------------------------------------------

Connection Pooling Configurationhttp://java.sun.com/products/jndi/tutorial/ldap/connect/config.html

java ldap 连接池_使用Ldap连接池相关推荐

  1. # 再次尝试 连接失败_新一代高效连接池HikariCP设计简要分析

    1 概述 应用程序建立与数据库的连接其实是一项开销很大的工作,其中涉及网络连接的建立.会话的建立.数据库端与应用程序的适配等诸多操作.因此,大部分情况下我们会选择将数据库连接进行池化管理. 连接池基本 ...

  2. mysql连接串_[MySQL] - MySQL连接字符串总结

    一.MySQL Connector/ODBC 2.50 (MyODBC 2.50)连接方式 1.本地数据库连接 Driver={MySQL};Server=localhost;Option=16834 ...

  3. java 线程亲缘性_亲缘性线程池,这是什么鬼?

    一.前言 JDK中的线程池主要解决两个问题: 一方面当执行大量异步任务时候线程池能够提供较好的性能,在不使用线程池的时,每当需要执行异步任务时候是直接 new一线程运行,而线程的创建和销毁是需要开销的 ...

  4. mysql配置数据库连接池_三种数据库连接池的配置

    三种数据库连接池的配置及使用(For JDBC) 连接池的优缺点 优点 使用连接池的最主要的优点是性能.创建一个新的数据库连接所耗费的时间主要取决于网络的速 度以及应用程序和数据库服务器的 ( 网络 ...

  5. 物联网流量池_物联网卡流量池系统的作用

    物联网卡的链接设备日新月异,企业中数以百计的设备开始加入物联网卡的连接网络系统.在帮助企业节约成本.提高效率的同时,物联网卡流量的分配和管理也存在着许多问题.如何均衡使用各个设备中的物联网卡流量成为企 ...

  6. python 大智慧股池_自设股票池(擒牛) 大智慧股票池

    量价推动(水涨船高的原理) --自设股票池(擒牛) 各位大智慧的投资朋友,鉴于目前市场震荡,行情以游资为首敢死队成为市场中的靓点. 那么游资的操作手法,快.准.狠,从布局,到拉升,时间短,扫单的速度很 ...

  7. python 大智慧股池_大智慧专业版股票池

    大智慧专业版股票池(分类:股票软件下载)大智慧专业版股票池是国内最权威,最专业,操作最便捷的一款精英型炒股软件. 大智慧专业版股票池的特点: 1.大智慧专业版股票池包含深度机构版.机构版.专业版等. ...

  8. 物联网流量池_物联网卡流量池

    原标题:物联网卡流量池 现如今物联网的发展如火如荼,物联网卡更是应用于我们生活中的很多智能设备,很大程度上方便了我们的生活.物联网卡是由移动.电信.联通运营商提供的2/3/4G卡,外观与普通SIM卡基 ...

  9. java 手机 连接电脑_手机无法连接电脑 java无法上传的常见解决办法

    首先下面的方法并不能肯定一次帮你解决问题,也许需要反复尝试或者并不需要完全按照下面方法作就能解决,祝你幸运 mpt无法连接手机,抛出现没有连接好的现象外,直接到控制面板里的调制解调器中察看 是否有mo ...

最新文章

  1. 虚拟机看服务器mac地址,虚拟机修改服务器mac地址吗
  2. pandas使用groupby函数计算dataframe数据中每个分组的N个数值的滚动最小值(rolling min)、例如,计算某公司的多个店铺每N天(5天)的滚动销售额最小值
  3. php 输出可以设置格式文件,php格式输出文件var_export函数实例
  4. 需要vmwareinstalldisk上的文件vmnet_手机上一键就能进行PDF与其他文件的相互转换,果然厉害到不行...
  5. Swiper学习之二---swiper的配置选项 ①
  6. 在Altium Designer中利用阵列粘贴功能快速绘制元器件封装
  7. mfc 使打开的窗口至于最顶层_MFC界面开发控件BCG帮助文档——功能区设计器(2)
  8. bottle框架学习(四)之模版进阶使用
  9. 拓端tecdat|R语言分类回归决策树交互式修剪和更美观地可视化分析细胞图像分割数据集
  10. 基于tensorflow的RNN中文自动写诗程序
  11. EXCEL 制作多簇并列的堆积柱形图
  12. ppt流程图箭头分叉_PPT实用模版大全(最全箭头、流程图).ppt
  13. np.random.binomial()
  14. Work from home
  15. 如何快速实现增长App用户量?
  16. 15款最佳的MySQL管理工具和应用程序
  17. android 微信点赞功能,Android 仿微信点赞和评论弹出框
  18. NTP时间同步器(时钟同步器)对于网络的重要性
  19. 数字滤波算法(一)——滑动平均滤波算法
  20. kindEditor和syntaxHighLighter的使用

热门文章

  1. Coins POJ - 1742(题解)
  2. vue2.0 实现click点击当前li,动态切换class
  3. VC++2013出现bug: 无法打开源文件“stdafx.h”
  4. 从源代码角度分析ViewStub 疑问与原理
  5. 第85讲:Scala中For表达式的强大表现力实战
  6. ExecuteScaler的三种返回值。
  7. 【Knockout】二、监控属性Observables
  8. js定时器、高亮修改单元格背景色
  9. careercup-链表 2.1
  10. 键盘消息捕获--MFC