惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - BigOrang

在vim中搜索关键字 linux top快捷键 -Xmx3G -Xms2G 在已经指定了最小内存2G后,启动的时候,就会直接分配2G给jvm吗 ?还是动态从1m到2G逐步分配的 java8类加载器示例&类加载1.8和1.8+的区别 windows查看端口占用 vmware Docker 设置代理 腾讯云域名托管到 cloudflare nginx 代理eureka后css/js/fonts无法访问 docker 基础镜像损坏 一起来找bug茬-01 mysql SHOW PROFILE 将所有容器docker都重启, 但是不重启mysql 正则 .*? 和 .* 的区别是什么 nginx打印所有配置内容 NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder kubesphere org.tmatesoft.svn.core.SVNException: svn: E160013: '/leifengyang/yygh-parent.git' path not found: 404 Not Found (https://gitee.com) 布隆过滤器原理及应用场景 linux中,使用alias, 应该在/etc/bashrc 中写,还是~/.bashrc中写,哪个更好 java date 时间最大连续天数
druid 获取数据库连接失败,一直wait.DruidDataSource.takeLast
BigOrang · 2025-08-31 · via 博客园 - BigOrang

at sun.misc.Unsafe.park(Native Method)

  • parking to wait for <0x0000000780199268> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
    at com.alibaba.druid.pool.DruidDataSource.takeLast(DruidDataSource.java:1448)
    at com.alibaba.druid.pool.DruidDataSource.getConnectionInternal(DruidDataSource.java:1090)

问题:

高并发场景,Druid获取数据库连接 一直等待 ,获取不了数据库链接; 服务tomcat线程占满,无响应

解决办法:

  • 确保 spring.datasource.maxWait 不为 -1, -1表示获取链接时不超时(永久等待), 可以配置为6000, 参考配置

  • 没有采用druid starter的情况下, 可以试下在代码中手动配置 DataSource

@Slf4j
@Configuration
public class DruidConfig {
    @Value("${spring.datasource.url}")
    private String dbUrl;
    @Value("${spring.datasource.username}")
    private String username;
    @Value("${spring.datasource.password}")
    private String password;
    @Value("${spring.datasource.druid.username:admin}")
    private String druidUsername;
    @Value("${spring.datasource.druid.password:hd123}")
    private String druidPassword;
    @Value("${spring.datasource.driver-class-name:com.mysql.jdbc.Driver}")
    private String driverClassName;
    @Value("${spring.datasource.initialSize:10}")
    private int initialSize;
    @Value("${spring.datasource.minIdle:10}")
    private int minIdle;
    @Value("${spring.datasource.maxActive:1000}")
    private int maxActive;
    @Value("${spring.datasource.maxWait:-1}")
    private int maxWait;
    @Value("${spring.datasource.timeBetweenEvictionRunsMillis:60000}")
    private int timeBetweenEvictionRunsMillis;
    @Value("${spring.datasource.minEvictableIdleTimeMillis:1800000}")
    private int minEvictableIdleTimeMillis;
    @Value("${spring.datasource.validationQuery:SELECT 1}")
    private String validationQuery;
    @Value("${spring.datasource.testWhileIdle:true}")
    private boolean testWhileIdle;
    @Value("${spring.datasource.testOnBorrow:false}")
    private boolean testOnBorrow;
    @Value("${spring.datasource.testOnReturn:false}")
    private boolean testOnReturn;
    @Value("${spring.datasource.poolPreparedStatements:true}")
    private boolean poolPreparedStatements;
    @Value("${spring.datasource.filters:stat,log4j}")
    private String filters;
    @Value("${spring.datasource.logSlowSql:true}")
    private String logSlowSql;

    public DruidConfig() {
    }

    @Bean
    public ServletRegistrationBean druidServlet() {
        ServletRegistrationBean reg = new ServletRegistrationBean();
        reg.setServlet(new StatViewServlet());
        reg.addUrlMappings(new String[]{"/druid/*"});
        reg.addInitParameter("loginUsername", this.druidUsername);
        reg.addInitParameter("loginPassword", this.druidPassword);
        reg.addInitParameter("logSlowSql", this.logSlowSql);
        return reg;
    }

    @Bean
    @Primary
    public DataSource druidDataSource() {
        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(this.dbUrl);
        datasource.setUsername(this.username);
        datasource.setPassword(this.password);
        datasource.setDriverClassName(this.driverClassName);
        datasource.setInitialSize(this.initialSize);
        datasource.setMinIdle(this.minIdle);
        datasource.setMaxActive(this.maxActive);
        datasource.setMaxWait(this.maxWait);
        datasource.setTimeBetweenEvictionRunsMillis(this.timeBetweenEvictionRunsMillis);
        datasource.setMinEvictableIdleTimeMillis(this.minEvictableIdleTimeMillis);
        datasource.setValidationQuery(this.validationQuery);
        datasource.setTestWhileIdle(this.testWhileIdle);
        datasource.setTestOnBorrow(this.testOnBorrow);
        datasource.setTestOnReturn(this.testOnReturn);
        datasource.setPoolPreparedStatements(this.poolPreparedStatements);
        datasource.setConnectionInitSqls(Collections.singletonList("set names utf8mb4"));

        try {
            datasource.setFilters(this.filters);
        } catch (SQLException var3) {
            log.error("druid configuration initialization filter", var3);
        }

        return datasource;
    }
}