【问题标题】:c3p0 ComboPooledDataSource report largest pool size?c3p0 ComboPooledDataSource 报告最大池大小?
【发布时间】:2011-08-13 22:10:51
【问题描述】:

我正在为使用 c3p0 的 ComboPooledDataSource 的网络应用程序实现一些运行时报告。我想知道是否有办法以编程方式获得迄今为止池中最大数量的连接。与ThreadPoolExecutor.getLargestPoolSize() 效果相同的东西。

我可以在ComboPooledDataSource 上看到许多报告方法,但一直找不到类似的东西。似乎没有任何(有意义的)c3p0 javadocs 并没有帮助。

【问题讨论】:

    标签: java reporting c3p0


    【解决方案1】:

    我搜索了 API,但找不到任何东西。这是我的简单解决方法:

    static final ComboPooledDataSource dataSource = new ComboPooledDataSource();
    
    static volatile int largestPoolSize = 0;
    
    public static Connection getConnection() throws SQLException {
        Connection connection = dataSource.getConnection();
        updateLargestPoolSize();
        return connection;
    }
    
    private static void updateLargestPoolSize() throws SQLException {
        int numConnections = dataSource.getNumConnections();
        if (numConnections > largestPoolSize) {
            largestPoolSize = numConnections;
        }
    }
    

    如果有人可以提出更复杂的建议,请发布。

    【讨论】:

      猜你喜欢
      • 2013-05-31
      • 1970-01-01
      • 2019-08-04
      • 2012-09-07
      • 2017-06-19
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多