光著膀子寫程序

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            2 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks
           來源: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 閱讀(3168) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 若羌县| 青浦区| 贡山| 偏关县| 尼玛县| 英山县| 南华县| 苍南县| 湘潭县| 吉木乃县| 望江县| 永德县| 资中县| 营山县| 孟州市| 翁源县| 五莲县| 义马市| 句容市| 格尔木市| 堆龙德庆县| 石渠县| 化隆| 湛江市| 平邑县| 尖扎县| 罗山县| 工布江达县| 利川市| 湟中县| 诸暨市| 襄樊市| 巴里| 固始县| 玛沁县| 皮山县| 榆树市| 鄂伦春自治旗| 新蔡县| 增城市| 栖霞市|