[alibaba/easyexcel]多线程写入excel数据出现主线程完成 关闭流,但是easyexcel异步没写完导致数据丢失

2024-02-21 103 views
6

怎么监控写入状态,需要判断数据都写完再去关闭流

回答

2

在线程里用CountDownLatch等线程工具

0

用flink写的,能拿到flink结束但是flink结束之后easyexcel数据没写完 代码: public void processElement(Tuple2<Integer, List<Tuple3<Integer, List<List>, Integer>>> value, ProcessFunction<Tuple2<Integer, List<Tuple3<Integer, List<List>, Integer>>>, Object>.Context ctx, Collector out) throws Exception { Integer patientCount = value.f0; List<Tuple3<Integer, List<List>, Integer>> f1 = value.f1; AtomicInteger i = new AtomicInteger(); f1.forEach(of->{ Integer sheet = of.f0; List<List> lists = of.f1; synchronized (map) { excelWriter.write(lists, map.get(sheet)); i.getAndIncrement(); } }); getRuntimeContext().getAccumulator(taskId + "-handle").add(patientCount.longValue()); 业务上来说这边已经调用了write()方法,但是easyexcel没写完数据,拿不到什么时候write完成状态