Showing
1 changed file
with
29 additions
and
1 deletions
@@ -38,6 +38,9 @@ import java.nio.charset.StandardCharsets; | @@ -38,6 +38,9 @@ import java.nio.charset.StandardCharsets; | ||
38 | import java.security.*; | 38 | import java.security.*; |
39 | import java.security.spec.PKCS8EncodedKeySpec; | 39 | import java.security.spec.PKCS8EncodedKeySpec; |
40 | import java.util.*; | 40 | import java.util.*; |
41 | +import java.util.concurrent.ArrayBlockingQueue; | ||
42 | +import java.util.concurrent.ThreadPoolExecutor; | ||
43 | +import java.util.concurrent.TimeUnit; | ||
41 | 44 | ||
42 | /** | 45 | /** |
43 | * Created by li.ma on 2020/3/31. | 46 | * Created by li.ma on 2020/3/31. |
@@ -63,6 +66,8 @@ public class ProductChainService { | @@ -63,6 +66,8 @@ public class ProductChainService { | ||
63 | @Value("${urltrainblock.url}") | 66 | @Value("${urltrainblock.url}") |
64 | private String urltrainblockUrl; | 67 | private String urltrainblockUrl; |
65 | 68 | ||
69 | + private ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 1, TimeUnit.HOURS, new ArrayBlockingQueue<>(10000)); | ||
70 | + | ||
66 | // curl http://40.73.0.117:8078/yoho/post/query POST -H "Content-Type:application/json" -d '"id":"156663177401529"' -v | 71 | // curl http://40.73.0.117:8078/yoho/post/query POST -H "Content-Type:application/json" -d '"id":"156663177401529"' -v |
67 | public void postQuery(Long chainId, String tagid) { | 72 | public void postQuery(Long chainId, String tagid) { |
68 | // (String serviceName, String url, Object request, Class<T> responseType, T fallback, int timeout) | 73 | // (String serviceName, String url, Object request, Class<T> responseType, T fallback, int timeout) |
@@ -92,10 +97,27 @@ public class ProductChainService { | @@ -92,10 +97,27 @@ public class ProductChainService { | ||
92 | } | 97 | } |
93 | 98 | ||
94 | 99 | ||
100 | + private class SynChainThread implements Runnable { | ||
101 | + public SynChainThread(){} | ||
95 | 102 | ||
103 | + public SynChainThread(Map<String, Object> request, Long id, String sign) { | ||
104 | + this.request = request; | ||
105 | + this.id = id; | ||
106 | + this.sign = sign; | ||
107 | + } | ||
96 | 108 | ||
97 | - public void postChainInfo(Map<String, Object> request, Long id, String sign) { | 109 | + private Map<String, Object> request; |
110 | + | ||
111 | + private Long id; | ||
112 | + | ||
113 | + private String sign; | ||
114 | + | ||
115 | + @Override | ||
116 | + public void run() { | ||
117 | + postChainInfo(request, id, sign); | ||
118 | + } | ||
98 | 119 | ||
120 | + public void postChainInfo(Map<String, Object> request, Long id, String sign) { | ||
99 | HttpHeaders headers = getHttpHeaders(sign); | 121 | HttpHeaders headers = getHttpHeaders(sign); |
100 | HttpEntity<String> formEntity = getStringHttpEntity(request, headers); | 122 | HttpEntity<String> formEntity = getStringHttpEntity(request, headers); |
101 | ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/info", formEntity, String.class); | 123 | ResponseEntity<String> response = restTemplate.postForEntity(urltrainblockUrl + "/post/info", formEntity, String.class); |
@@ -109,6 +131,12 @@ public class ProductChainService { | @@ -109,6 +131,12 @@ public class ProductChainService { | ||
109 | updateIsupload(id, 1); // 如果更新成功,则更新数据库字段 | 131 | updateIsupload(id, 1); // 如果更新成功,则更新数据库字段 |
110 | } | 132 | } |
111 | } | 133 | } |
134 | + } | ||
135 | + | ||
136 | + | ||
137 | + public void aSynPostChainInfo(Map<String, Object> request, Long id, String sign) { | ||
138 | + executor.submit(new SynChainThread(request, id, sign)); | ||
139 | + } | ||
112 | 140 | ||
113 | // SELECT * FROM ${TABLE_PRODUCT_CHAIN} WHERE transaction_id IS NULL | 141 | // SELECT * FROM ${TABLE_PRODUCT_CHAIN} WHERE transaction_id IS NULL |
114 | public List<ProductChain> queryProductChain() { | 142 | public List<ProductChain> queryProductChain() { |
-
Please register or login to post a comment