光著膀子寫(xiě)程序

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            2 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks
           來(lái)源: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 Timeout

          The 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 Pooling

          Pooled 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 Configuration

          http://java.sun.com/products/jndi/tutorial/ldap/connect/config.html
          posted on 2005-08-01 17:21 Hut 閱讀(3170) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 汨罗市| 重庆市| 东平县| 盐池县| 金昌市| 图木舒克市| 舞阳县| 兴和县| 邯郸县| 岐山县| 吕梁市| 平昌县| 滦平县| 项城市| 武城县| 长顺县| 综艺| 武川县| 南汇区| 通榆县| 永吉县| 鸡东县| 通化市| 桃园市| 达尔| 云龙县| 尉氏县| 肥城市| 石台县| 乌兰察布市| 沙田区| 镇平县| 乌苏市| 丰原市| 芜湖市| 双柏县| 定州市| 濮阳县| 扶风县| 葫芦岛市| 龙山县|