Skip to content

建议对springboot增加连接池组件 #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
k4n5ha0 opened this issue Dec 23, 2018 · 5 comments
Closed

建议对springboot增加连接池组件 #60

k4n5ha0 opened this issue Dec 23, 2018 · 5 comments
Labels
Enhancement 增强 增强功能、提高性能等

Comments

@k4n5ha0
Copy link

k4n5ha0 commented Dec 23, 2018

我看了一下工程目录 似乎没有使用数据库连接池
直接操作jdbc对性能影响很大
希望作者 提供连接池相关的技术支持
谢谢
另外建议使用undertow以替换tomcat
undertow性能比tomcat好很多

@TommyLemon
Copy link
Collaborator

因为 Demo 只是用来简单上手的,尽可能少引入第三方库。
Undertow 暂不考虑,Web 容器还是 Tomcat 更主流上手简单;
连接池倒是比较刚需的,考虑用 Druid 在 Demo 工程内实现。

@TommyLemon TommyLemon self-assigned this Dec 24, 2018
@TommyLemon TommyLemon added the Enhancement 增强 增强功能、提高性能等 label Dec 24, 2018
@TommyLemon TommyLemon removed their assignment Dec 24, 2018
@yangjinju
Copy link

@TommyLemon 目前连接池管理是否已经完善了?

@TommyLemon
Copy link
Collaborator

TommyLemon commented Nov 17, 2020

@yangjinju

可以在 DemoSQLExecutor 重写 getConnection
https://github.com/APIJSON/APIJSON-Demo/blob/master/APIJSON-Java-Server/APIJSONBoot/src/main/java/apijson/demo/DemoSQLExecutor.java

public Connection getConnection(..) {
  Connection c = connectionMap.get(config.getDatabase());
  if (c == null || c.isClosed()) {
    c = DruidConfig.DATA_SOURCE.getConnection();
    connectionMap.put(config.getDatabase(), c);  // DruidConfig 初始化获取到 Datasource 后给静态变量 DATA_SOURCE 赋值,或者也可以试试 ApplicationContext.getBean(DruidConfig.class).getDataSource()
  }
  return super.getConnection(..);  // 必须最后执行,因为里面还有事务相关处理。如果这里是 return c,则会导致 增删改 多个对象时只有第一个会 commit,即只有第一个对象成功插入数据库表
}

@TommyLemon
Copy link
Collaborator

@TommyLemon
Copy link
Collaborator

TommyLemon commented Jun 21, 2021

@TommyLemon 目前连接池管理是否已经完善了?

@k4n5ha0 @yangjinju 已完善。

新增数据源关键词 @Datasource,可由业务完全自定义
https://github.com/Tencent/APIJSON/releases/tag/4.7.0

新增 连接池及多数据源 Demo(Druid + HikariCP)
https://gitee.com/APIJSON/APIJSON-Demo/tree/master/APIJSON-Java-Server

@k4n5ha0 k4n5ha0 closed this as completed Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 增强 增强功能、提高性能等
Projects
None yet
Development

No branches or pull requests

3 participants