Caused by: java.net.SocketTimeoutException: Read timed out;

Cause: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.; An I/O error occurred while sending to the backend.; nested exception is org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.

Caused by: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.

Caused by: java.net.SocketTimeoutException: Read timed out;

最近在做一个复杂查询,数据量比较大,需要二十多秒才能返回得结果,提交了请求之后还没等结果吐出来就报错了,发现是因为没有添加超时配置,所以在查询又或者读取的时候超时了,我这里是读取的时候超时了,既然超时了直接把超时时间延长就好了,我用的是druid(德鲁伊)

在数据库url补上两个参数 socketTimeout=300000&loginTimeout=60000

spring:

datasource:

url: jdbc:postgresql://localhost:3306/yourdb?socketTimeout=300000&loginTimeout=60000

或者

connection-timeout: 60000 # 建立连接超时:60秒

socket-timeout: 300000 # Socket读取超时:5分钟

query-timeout: 180000 # 查询执行超时:3分钟

相关推荐
迎風吹頭髮5 分钟前
Linux内核架构浅谈44-Linux slab分配器:通用缓存与专用缓存的创建与使用
linux·spring·架构
m0_736927046 分钟前
想抓PostgreSQL里的慢SQL?pg_stat_statements基础黑匣子和pg_stat_monitor时间窗,谁能帮你更准揪出性能小偷?
java·数据库·sql·postgresql
Jabes.yang9 分钟前
Java面试大作战:从缓存技术到音视频场景的探讨
java·spring boot·redis·缓存·kafka·spring security·oauth2
hbqjzx10 分钟前
记录一个自动学习的脚本开发过程
开发语言·javascript·学习
Query*23 分钟前
Java 设计模式——适配器模式进阶:原理深挖、框架应用与实战扩展
java·设计模式·适配器模式
Sirens.32 分钟前
Java核心概念:抽象类、接口、Object类深度剖析
java·开发语言·github
Meteors.33 分钟前
23种设计模式——中介者模式 (Mediator Pattern)详解
java·设计模式·中介者模式
望获linux35 分钟前
【实时Linux实战系列】使用 u-trace 或 a-trace 进行用户态应用剖析
java·linux·前端·网络·数据库·elasticsearch·操作系统
焰火199942 分钟前
[Java]基于Spring的轻量级定时任务动态管理框架
java·后端
Seven971 小时前
Springboot 常见面试题汇总
java·spring boot