Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the connection pool in Grails3

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to change the connection pool in Grails3". In the daily operation, I believe many people have doubts about how to change the connection pool in Grails3. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubts about "how to change the connection pool in Grails3". Next, please follow the editor to study!

Grails3 default database connection pool is tomcat-jdbc pool, and its performance is much worse than that of druid and HikariCP, so I want to change it to another connection pool.

Since tomcat-jdbc connection pooling is used by default, dependencies need to be removed

/ / runtime "com.h3database:h3" / / runtime "org.apache.tomcat:tomcat-jdbc" / / add Alibaba druid connection pool compile group: 'com.alibaba', name:' druid', version: '1.1.18'compile' mysql:mysql-connector-java:5.1.40'

Grails-app/conf/applicaiton.yml configuration should also comment out the default connection pool

DataSource:# pooled: true jmxExport: true driverClassName: com.mysql.jdbc.Driver username: root password: root dialect: org.hibernate.dialect.MySQL5InnoDBDialect url: jdbc:mysql://localhost:3306/g3?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false # to be compatible with grails, let Hibernate build tables automatically So add the configuration related to connection pool under dataSource druid: minIdle: 1 maxActive: 40 maxWait: 60000 initialSize: 20 testWhileIdle: true testOnBorrow: false testOnReturn: false removeAbandoned: true filters: stat,wall Slf4j validationQuery: select 'x' useGlobalDataSourceStat: true poolPreparedStatements: true minEvictableIdleTimeMillis: 300000 timeBetweenEvictionRunsMillis: 60000 connectionProperties: clientEncoding=UTF-8 maxPoolPreparedStatementPerConnectionSize: 20environments: development: dataSource: dbCreate: create-drop url: jdbc:mysql://localhost:3306/g3?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false test: dataSource: dbCreate: update Url: jdbc:mysql://localhost:3306/g3?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false production: dataSource: dbCreate: update url: jdbc:mysql://localhost:3306/g3?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=falseserver: port: 8081 # TRANSACTION_READ_COMMITTED

Grails-app/conf/spring/resources.groovy configuration

/ / Place your Spring DSL code herebeans = {/ / Monitoring management page configuration (administrative username, password) druidConsoleServlet (org.springframework.boot.web.servlet.ServletRegistrationBean) {servlet = bean (com.alibaba.druid.support.http.StatViewServlet) urlMappings = ["/ druid/*"] / / urlMappings = ["* .js", "* .gif", "* .jpg", "* .png", "* .css", "* .ico" "/ druid/*"] initParameters = ["loginUsername": "root", "loginPassword": "123456", "allow": "127.0.0.1" "deny": "] / / loadOnStartup = 2} / / alibaba druid configuration dataSource (com.alibaba.druid.pool.DruidDataSource) {bean-> bean.initMethod = 'init' bean.destroyMethod =' close' driverClassName = grailsApplication.config.dataSource.driverClassName url = grailsApplication.config.dataSource.url username = grailsApplication.config.dataSource.username Password = grailsApplication.config.dataSource.password initialSize = grailsApplication.config.dataSource.druid.initialSize minIdle = grailsApplication.config.dataSource.druid.minIdle maxActive = grailsApplication.config.dataSource.druid.maxActive maxWait = grailsApplication.config.dataSource.druid.maxWait timeBetweenEvictionRunsMillis = grailsApplication.config.dataSource.druid.timeBetweenEvictionRunsMillis minEvictableIdleTimeMillis = grailsApplication.config.dataSource.druid.minEvictableIdleTimeMillis validationQuery = grailsApplication.config.dataSource.druid.validationQuery removeAbandoned = grailsApplication.config.dataSource.druid. RemoveAbandoned testWhileIdle = grailsApplication.config.dataSource.druid.testWhileIdle connectionProperties = grailsApplication.config.dataSource.druid.connectionProperties testOnBorrow = grailsApplication.config.dataSource.druid.testOnBorrow poolPreparedStatements = grailsApplication.config.dataSource.druid.poolPreparedStatements testOnReturn = grailsApplication.config.dataSource.druid.testOnReturn useGlobalDataSourceStat = grailsApplication.config.dataSource.druid.useGlobalDataSourceStat maxPoolPreparedStatementPerConnectionSize = grailsApplication.config.dataSource.druid.maxPoolPreparedStatementPerConnectionSize filters = grailsApplication.config.dataSource.druid.filters}}

Grails-app/conf/logback.groovy add Log configuration

/ / logger for log collection ('com.alibaba', DEBUG, [' STDOUT'], false)

Start the project and the log appears

2019-07-03 03 0315 main 06.691 WARN-[main] com.alibaba.druid.pool.DruidDataSource: removeAbandoned is true, not use in productiion.2019-07-03 03 315V 07.078 INFO-[main] com.alibaba.druid.pool.DruidDataSource: {dataSource-1} initedGrails application running at http://localhost:8081 in environment: development

Web monitoring address

Http://127.0.0.1:8081/druid/index.html at this point, the study on "how to change the connection pool in Grails3" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report