未验证 提交 af1c88a2 编写于 作者: J James 提交者: GitHub

下载图片添加连接和读取的超时设置

在默认情况下,如果连接成功建立,但是下载速度极慢,在 Spring Web 应用中同步执行 Excel 的导出任务,会造成线程长时间被占用,最终造成 Tomcat 连接数超限,对应用造成毁灭性灾难。
上级 5797cb34
......@@ -3,6 +3,7 @@ package com.alibaba.excel.converters.url;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
......@@ -39,8 +40,12 @@ public class UrlImageConverter implements Converter<URL> {
GlobalConfiguration globalConfiguration) throws IOException {
InputStream inputStream = null;
try {
inputStream = value.openStream();
byte[] bytes = IoUtils.toByteArray(inputStream);
URLConnection conn = value.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(5000);
inputStream = con.getInputStream();
byte[] bytes = IoUtils.toByteArray(inputStream);
return new CellData(bytes);
} finally {
if (inputStream != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册