scala 光滑的连接池?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15534777/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connection pooling in slick?
提问by Pablo Fernandez
采纳答案by Rogach
I use Apache Commons DBCPfor this. Basically, you simply create a DataSource, that encapsulates the pooling details, and pass that DataSourceto Slick:
我用Apache Commons DBCP这个。基本上,您只需创建一个DataSource, 封装池化细节,并将其传递DataSource给 Slick:
import org.apache.commons.dbcp.BasicDataSource
val dataSource: DataSource = {
val ds = new BasicDataSource
ds.setDriverClassName("org.hsqldb.jdbc.JDBCDriver")
ds.setUsername("SA")
ds.setPassword("")
ds.setMaxActive(20);
ds.setMaxIdle(10);
ds.setInitialSize(10);
ds.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS")
new java.io.File("target").mkdirs // ensure that folder for database exists
ds.setUrl("jdbc:hsqldb:file:target/db/db")
ds
}
// test the data source validity
dataSource.getConnection().close()
// get the Slick database that uses the pooled connection
val database = Database.forDataSource(dataSource)
This example uses HSQLDB, but can be easily adapted to any other database.
此示例使用 HSQLDB,但可以轻松适应任何其他数据库。
Full example is here(you can clone the project, and run sbt runin lift/ directory to see it working).
完整示例在这里(您可以克隆项目,并sbt run在 lift/ 目录中运行以查看它的工作情况)。
回答by Pablo Fernandez
For completion I ended up writing a blog post about this:
为了完成,我最终写了一篇关于这个的博客文章:
http://fernandezpablo85.github.io/2013/04/07/slick_connection_pooling.html
http://fernandezpablo85.github.io/2013/04/07/slick_connection_pooling.html
回答by nemoo
Play 2.4 now uses HikariCP which looks really nice: https://brettwooldridge.github.io/HikariCP/https://www.playframework.com/documentation/2.4.x/SettingsJDBC
Play 2.4 现在使用看起来非常不错的 HikariCP:https ://brettwooldridge.github.io/HikariCP/ https://www.playframework.com/documentation/2.4.x/SettingsJDBC
回答by Michael Nash
It appears as though the later version of play pool configured connections - see http://www.playframework.com/documentation/2.0.1/SettingsJDBC
看起来好像是更高版本的游戏池配置了连接 - 请参阅http://www.playframework.com/documentation/2.0.1/SettingsJDBC

