有些教程说使用 org.postgresql.ds.PGConnectionPoolDataSource
但有些教程说只是 org.postgresql.ds.PGSimpleDataSource
...两者之间有什么区别?
最佳答案
不同之处在于类 org.postgresql.ds.PGConnectionPoolDataSource
实现了连接池,因此它可以提供一些性能优势。
根据文档:
Simple DataSource which does not perform connection pooling. In order to use the DataSource, you must set the property databaseName. The settings for serverName, portNumber, user, and password are optional. Note: these properties are declared in the superclass.
Class PGConnectionPoolDataSource
PostgreSQL implementation of ConnectionPoolDataSource. The app server or middleware vendor should provide a DataSource implementation that takes advantage of this ConnectionPoolDataSource. If not, you can use the PostgreSQL implementation known as PoolingDataSource, but that should only be used if your server or middleware vendor does not provide their own. Why? The server may want to reuse the same Connection across all EJBs requesting a Connection within the same Transaction, or provide other similar advanced features.
另见:
关于postgresql - Postgres Glassfish 池化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21634169/