许鹏程
2023-06-30 3bbfaa3d7d416afbd154576453c8ee9e7e2f8899
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//package com.product.kt.test.service;
//
//import java.util.List;
//import java.util.concurrent.Future;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.scheduling.annotation.AsyncResult;
//import org.springframework.stereotype.Component;
//
//import com.product.core.entity.FieldSetEntity;
//
//
//@Component
//public class SyncToolsHandler {
//
//    private static final Logger LOG = LoggerFactory.getLogger(SyncToolsHandler.class);
//
//    @Autowired
//    WriteToolService writeToolService;
//
//    /**
//     * 异步执行
//     *
//     * @param readToolList
//     * @param pageIndex
//     * @return
//     */
////    @Async("ToolTask")
//    public Future<String> syncTools(List<FieldSetEntity> readToolList, int pageIndex, String tableName, String timeField) {
//
//        System.out.println("thread name " + Thread.currentThread().getName());
//
//        LOG.info(String.format("此批数据的段数为:%s 此段数据的数据条数为:%s", pageIndex, readToolList.size()));
//
//        //声明future对象
//        Future<String> result = new AsyncResult<String>("");
//
//        //循环遍历
//        if (null != readToolList && readToolList.size() > 0) {
//            try {
//                int listSize = readToolList.size();
//                int listStart = 0, listEnd = 0;
//                int ropeNum = listSize / 2000;
//
//                for (int i = 0; i < ropeNum; i++) {
//                    //数据入库操作
//                    listStart = i * 2000;
//                    listEnd = i * 2000 + 2000;
//                    writeToolService.writeData(readToolList.subList(listStart, listEnd), tableName, timeField);
//                }
//                writeToolService.writeData(readToolList.subList(listEnd, listSize), tableName, timeField);
//
//            } catch (Exception e) {
//                //记录出现异常的时间,线程name
//                result = new AsyncResult<String>("fail,time=" + System.currentTimeMillis() + ",thread id=" + Thread.currentThread().getName() + ",pageIndex=" + pageIndex);
//            }
//        }
//        return result;
//    }
//}