Commit 6e85a658ef319cdd39ac6c81c5950d65d00d8f75
1 parent
2366d8404b
Exists in
master
and in
6 other branches
删除了自己没有引用的工具类和注释了sout注释
Showing 2 changed files with 2 additions and 111 deletions
platform-operate-api/src/main/java/com/lyms/platform/operate/web/utils/FixedThreadPoolUtil.java
View file @
6e85a65
1 | -package com.lyms.platform.operate.web.utils; | |
2 | - | |
3 | -import java.util.ArrayList; | |
4 | -import java.util.List; | |
5 | -import java.util.concurrent.CountDownLatch; | |
6 | -import java.util.concurrent.ExecutorService; | |
7 | -import java.util.concurrent.Executors; | |
8 | - | |
9 | -public class FixedThreadPoolUtil { | |
10 | - | |
11 | - public static void exec(List<Object> list) throws InterruptedException { | |
12 | - int count = 30000; //一个线程处理300条数据 | |
13 | - int listSize = list.size(); //数据集合大小 | |
14 | - int runSize = (listSize / count) + 1; //开启的线程数 | |
15 | - if (runSize>10){//线程数最大设置30个,自己定义的 | |
16 | - runSize=10; | |
17 | - count= listSize/runSize; | |
18 | - } | |
19 | - List<Object> newlist = null; //存放每个线程的执行数据 | |
20 | - ExecutorService executor = Executors.newFixedThreadPool(runSize); //创建一个线程池,数量和开启线程的数量一样 | |
21 | - //创建两个个计数器 | |
22 | - CountDownLatch begin = new CountDownLatch(1); | |
23 | - CountDownLatch end = new CountDownLatch(runSize); | |
24 | - //循环创建线程 | |
25 | - for (int i = 0; i < runSize; i++) { | |
26 | - //计算每个线程执行的数据 | |
27 | - if ((i + 1) == runSize) { | |
28 | - int startIndex = (i * count); | |
29 | - int endIndex = list.size(); | |
30 | - newlist = list.subList(startIndex, endIndex); | |
31 | - } else { | |
32 | - int startIndex = (i * count); | |
33 | - int endIndex = (i + 1) * count; | |
34 | - newlist = list.subList(startIndex, endIndex); | |
35 | - } | |
36 | - //线程类 | |
37 | - MyThread mythead = new MyThread(newlist, begin, end); | |
38 | - //这里执行线程的方式是调用线程池里的executor.execute(mythead)方法。 | |
39 | - executor.execute(mythead); | |
40 | - } | |
41 | - | |
42 | - begin.countDown(); | |
43 | - end.await(); | |
44 | - //执行完关闭线程池 | |
45 | - executor.shutdown(); | |
46 | - } | |
47 | - | |
48 | - //测试 | |
49 | -// public static void main(String[] args) { | |
50 | -// List<Object> list = new ArrayList<Object>(); | |
51 | -// long start=System.currentTimeMillis(); | |
52 | -// System.out.println("start==" + start); | |
53 | -// Strtest strtest=new Strtest("王明",1); | |
54 | -// //数据越大线程越多 | |
55 | -// for (int i = 0; i < 3000; i++) { | |
56 | -//// list.add("hello" + i); | |
57 | -// list.add(new Strtest(i+"王明",1+i)); | |
58 | -// } | |
59 | -// try { | |
60 | -// FixedThreadPoolUtil.exec(list); | |
61 | -// long end=System.currentTimeMillis(); | |
62 | -// System.out.println("end=="+end); | |
63 | -// System.out.println("end-start="+(end-start)); | |
64 | -// } catch (InterruptedException e) { | |
65 | -// e.printStackTrace(); | |
66 | -// } | |
67 | -// } | |
68 | -} | |
69 | - | |
70 | -class MyThread implements Runnable { | |
71 | - private List<Object> list; | |
72 | - private CountDownLatch begin; | |
73 | - private CountDownLatch end; | |
74 | - | |
75 | - //创建个构造函数初始化 list,和其他用到的参数 | |
76 | - public MyThread(List<Object> list, CountDownLatch begin, CountDownLatch end) { | |
77 | - this.list = list; | |
78 | - this.begin = begin; | |
79 | - this.end = end; | |
80 | - } | |
81 | - | |
82 | - @Override | |
83 | - public void run() { | |
84 | - try { | |
85 | - for (int i = 0; i < list.size(); i++) { | |
86 | - /* | |
87 | - 2: 具体插入实现在这里写 | |
88 | - */ | |
89 | - //这里还要说一下,,由于在实质项目中,当处理的数据存在等待超时和出错会使线程一直处于等待状态 | |
90 | - //这里只是处理简单的, | |
91 | - //分批 批量插入 | |
92 | -// Thread.sleep(3000); | |
93 | - System.out.println("当前线程名称:"+Thread.currentThread().getName()+"======存储的数据内容:"+i | |
94 | - ); | |
95 | - } | |
96 | - //执行完让线程直接进入等待 | |
97 | - begin.await(); | |
98 | - } catch (InterruptedException e) { | |
99 | - // TODO Auto-generated catch block | |
100 | - e.printStackTrace(); | |
101 | - } finally { | |
102 | - //这里要主要了,当一个线程执行完 了计数要减一不然这个线程会被一直挂起 | |
103 | - // ,end.countDown(),这个方法就是直接把计数器减一的 | |
104 | - end.countDown(); | |
105 | - } | |
106 | - } | |
107 | - | |
108 | - | |
109 | -} |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/worker/SyncV2HistoryWorkerx.java
View file @
6e85a65
... | ... | @@ -55,12 +55,12 @@ |
55 | 55 | if (patients != null) { |
56 | 56 | continue; |
57 | 57 | } |
58 | - //董勤让写死的 | |
58 | + | |
59 | 59 | list.setHospitalId("216");//todo |
60 | 60 | list.setBookbuildingDoctor("1000000185");//todo |
61 | 61 | list.setBookbuildingDate(DateUtil.getyyyy_MM_dd(new Date())); |
62 | 62 | p = bookbuildingFacade.addPregnantBookbuilding(list, null, false); |
63 | - System.out.println("当前线程名称:"+Thread.currentThread().getName()+"===保存好建档_id:"+p.getData()); | |
63 | + //System.out.println("当前线程名称:"+Thread.currentThread().getName()+"===保存好建档_id:"+p.getData()); | |
64 | 64 | } |
65 | 65 | return p; |
66 | 66 | } |