Skip to content

Commit 1bbbcb2

Browse files
author
zhangdingping
committed
...
1 parent 3d49045 commit 1bbbcb2

File tree

2 files changed

+81
-22
lines changed

2 files changed

+81
-22
lines changed

.idea/workspace.xml

Lines changed: 45 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ public class FileParser {
8989

9090
}
9191
```
92+
> 引入CountDownLatch,使得Excel解析快了一倍 1031→547
93+
```java
94+
public class ExcelParser {
95+
private StructableExcelVo doParse(Workbook wb) {
96+
97+
List<StructableFileVO> fileVOS = new CopyOnWriteArrayList<>();
98+
99+
int size = wb.getNumberOfSheets();
100+
101+
//1031毫秒降低到547毫秒 看来还是有点用的
102+
CountDownLatch latch = new CountDownLatch(size);
103+
for (int i = 0; i < size; i++) {
104+
//获取每个工作表
105+
Sheet sheet = wb.getSheetAt(i);
106+
107+
new Thread(new Runnable() {
108+
@Override
109+
public void run() {
110+
fileVOS.add(getSheetData(sheet));
111+
latch.countDown();
112+
}
113+
}).start();
114+
}
115+
try {
116+
//等待执行完毕
117+
latch.await();
118+
} catch (InterruptedException e) {
119+
e.printStackTrace();
120+
}
121+
StructableExcelVo excelVo = new StructableExcelVo();
122+
excelVo.setValues(fileVOS);
123+
124+
return excelVo;
125+
}
126+
}
127+
```
92128

93129
### 使用
94130
> 创建FileParser(com.deepz.fileparse.main),将文件上传后的输入流、文件名后缀(suffix)封装成FileDto对象作为入参,调用parse方法即可

0 commit comments

Comments
 (0)