【问题标题】:Can I access the c3P0 connection pool properties programmatically?我可以以编程方式访问 c3P0 连接池属性吗?
【发布时间】:2009-12-14 16:59:41
【问题描述】:

我担心我为 C3P0 连接池设置的属性没有被正确使用。

有没有一种方法可以访问应用程序运行时设置的值并将它们打印出来:

Println("最小连接数"+connectionNumers.minimum);

谢谢

【问题讨论】:

    标签: hibernate c3p0


    【解决方案1】:

    您可以使用 log4j 来输出调试信息,如下所示:

    log4j.logger.com.mchange=DEBUG, STDOUT
    
    ### direct log messages to stdout ###
    log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
    log4j.appender.STDOUT.Target=System.out
    log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
    log4j.appender.STDOUT.layout.ConversionPattern=%t %d{dd/MMM/yyyy:H:mm:ssZ} %5p %c{1}:%L - %m%n
    

    如果您将上述内容放入名为 log4j.properties 的文件中,并将该文件放入您的类路径中,您应该会从 c3p0 获得大量调试输出。

    示例输出:

    main 14/Dec/2009:13:24:49-0500 DEBUG BasicResourcePool:289 - com.mchange.v2.resourcepool.BasicResourcePool@16c06dd config: [start -> 0; min -> 0; max -> 5; inc -> 1; num_acq_attempts -> 30; acq_attempt_delay -> 1000; check_idle_resources_delay -> 300000; mox_resource_age -> 0; max_idle_time -> 100000; excess_max_idle_time -> 0; destroy_unreturned_resc_time -> 0; expiration_enforcement_delay -> 25000; break_on_acquisition_failure -> false; debug_store_checkout_exceptions -> false]
    main 14/Dec/2009:13:24:49-0500 DEBUG BasicResourcePool:538 - acquire test -- pool size: 0; target_pool_size: 0; desired target? 1
    main 14/Dec/2009:13:24:49-0500 DEBUG BasicResourcePool:404 - incremented pending_acquires: 1
    main 14/Dec/2009:13:24:49-0500 DEBUG BasicResourcePool:1291 - awaitAvailable(): [unknown]
    

    log4j

    【讨论】:

      【解决方案2】:

      API 允许您以编程方式访问这些属性。

      假设您有 ComboPooledDataSource 实例:

      static final ComboPooledDataSource dataSource = new ComboPooledDataSource();
      

      您可以在运行时访问这些属性,例如:

      int minPoolSize = dataSource.getMinPoolSize();
      

      加上一些其他有用的信息,例如:

      int numBusyConnections = dataSource.getNumBusyConnections();
      Throwable lastTestError = dataSource.getLastConnectionTestFailureDefaultUser();
      

      来源:http://www.mchange.com/projects/c3p0/apidocs/com/mchange/v2/c3p0/ComboPooledDataSource.html

      【讨论】:

        【解决方案3】:

        您想查看运行时信息还是想更改属性值?我不知道你可以在运行时更改属性值,因为这些配置值存储在 ram 中。

        【讨论】:

          猜你喜欢
          • 2021-04-22
          • 2011-02-24
          • 2022-01-18
          • 2012-05-19
          • 1970-01-01
          • 1970-01-01
          • 2021-03-05
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多